From a9a01cc6a08953d08e88767bf3f3f640f2016247 Mon Sep 17 00:00:00 2001 From: Rosco Kalis Date: Mon, 16 Dec 2024 16:15:23 +0100 Subject: [PATCH] fix: test --- app/[locale]/og.jpg/blog/[...slug]/route.tsx | 5 +++-- app/[locale]/og.jpg/blog/route.tsx | 5 +++-- app/[locale]/og.jpg/exploits/route.tsx | 5 +++-- app/[locale]/og.jpg/learn/[...slug]/route.tsx | 5 +++-- app/[locale]/og.jpg/learn/[category]/route.tsx | 5 +++-- app/[locale]/og.jpg/learn/faq/route.tsx | 2 +- app/[locale]/og.jpg/learn/route.tsx | 5 +++-- .../learn/wallets/add-network/[slug]/route.tsx | 5 +++-- .../og.jpg/learn/wallets/add-network/route.tsx | 5 +++-- .../og.jpg/token-approval-checker/[slug]/route.tsx | 5 +++-- lib/constants.ts | 2 ++ lib/utils/og.tsx | 12 ------------ 12 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/[locale]/og.jpg/blog/[...slug]/route.tsx b/app/[locale]/og.jpg/blog/[...slug]/route.tsx index 6ed31ca7..e8dad792 100644 --- a/app/[locale]/og.jpg/blog/[...slug]/route.tsx +++ b/app/[locale]/og.jpg/blog/[...slug]/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { getAllContentSlugs, readAndParseContentFile } from 'lib/utils/markdown-content'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; @@ -13,8 +14,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { const slugs = getAllContentSlugs('blog'); diff --git a/app/[locale]/og.jpg/blog/route.tsx b/app/[locale]/og.jpg/blog/route.tsx index 6b5668b4..490b884b 100644 --- a/app/[locale]/og.jpg/blog/route.tsx +++ b/app/[locale]/og.jpg/blog/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; import { getTranslations } from 'next-intl/server'; @@ -11,8 +12,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { return locales.map((locale) => ({ locale })); diff --git a/app/[locale]/og.jpg/exploits/route.tsx b/app/[locale]/og.jpg/exploits/route.tsx index 2f4335b7..0a2dee5d 100644 --- a/app/[locale]/og.jpg/exploits/route.tsx +++ b/app/[locale]/og.jpg/exploits/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; import { getTranslations } from 'next-intl/server'; @@ -11,8 +12,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { return locales.map((locale) => ({ locale })); diff --git a/app/[locale]/og.jpg/learn/[...slug]/route.tsx b/app/[locale]/og.jpg/learn/[...slug]/route.tsx index c1818894..7552a64f 100644 --- a/app/[locale]/og.jpg/learn/[...slug]/route.tsx +++ b/app/[locale]/og.jpg/learn/[...slug]/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { getAllContentSlugs, readAndParseContentFile } from 'lib/utils/markdown-content'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; @@ -13,8 +14,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { const slugs = getAllContentSlugs('learn'); diff --git a/app/[locale]/og.jpg/learn/[category]/route.tsx b/app/[locale]/og.jpg/learn/[category]/route.tsx index a02accd6..627d6298 100644 --- a/app/[locale]/og.jpg/learn/[category]/route.tsx +++ b/app/[locale]/og.jpg/learn/[category]/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { getAllLearnCategories } from 'lib/utils/markdown-content'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; @@ -13,8 +14,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { const categorySlugs = getAllLearnCategories(); diff --git a/app/[locale]/og.jpg/learn/faq/route.tsx b/app/[locale]/og.jpg/learn/faq/route.tsx index 8d0d622d..ae7e8726 100644 --- a/app/[locale]/og.jpg/learn/faq/route.tsx +++ b/app/[locale]/og.jpg/learn/faq/route.tsx @@ -11,7 +11,7 @@ interface Props { }; } -export const dynamic = 'error'; +export const dynamic = process.env.SKIP_OG_IMAGES === 'true' ? 'error' : 'force-dynamic'; export const dynamicParams = false; export const generateStaticParams = () => { diff --git a/app/[locale]/og.jpg/learn/route.tsx b/app/[locale]/og.jpg/learn/route.tsx index 00f5d575..dff2ec5e 100644 --- a/app/[locale]/og.jpg/learn/route.tsx +++ b/app/[locale]/og.jpg/learn/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; import { getTranslations } from 'next-intl/server'; @@ -11,8 +12,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { return locales.map((locale) => ({ locale })); diff --git a/app/[locale]/og.jpg/learn/wallets/add-network/[slug]/route.tsx b/app/[locale]/og.jpg/learn/wallets/add-network/[slug]/route.tsx index 2c2df1b0..51795fb7 100644 --- a/app/[locale]/og.jpg/learn/wallets/add-network/[slug]/route.tsx +++ b/app/[locale]/og.jpg/learn/wallets/add-network/[slug]/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { SUPPORTED_CHAINS, getChainIdFromSlug, getChainName, getChainSlug } from 'lib/utils/chains'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; @@ -13,8 +14,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { const slugs = SUPPORTED_CHAINS.map(getChainSlug); diff --git a/app/[locale]/og.jpg/learn/wallets/add-network/route.tsx b/app/[locale]/og.jpg/learn/wallets/add-network/route.tsx index 2f03ec16..efb7ab06 100644 --- a/app/[locale]/og.jpg/learn/wallets/add-network/route.tsx +++ b/app/[locale]/og.jpg/learn/wallets/add-network/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; import { getTranslations } from 'next-intl/server'; @@ -11,8 +12,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { return locales.map((locale) => ({ locale })); diff --git a/app/[locale]/og.jpg/token-approval-checker/[slug]/route.tsx b/app/[locale]/og.jpg/token-approval-checker/[slug]/route.tsx index f8ca0715..4b80829b 100644 --- a/app/[locale]/og.jpg/token-approval-checker/[slug]/route.tsx +++ b/app/[locale]/og.jpg/token-approval-checker/[slug]/route.tsx @@ -1,3 +1,4 @@ +import { SKIP_OG_IMAGES } from 'lib/constants'; import { locales } from 'lib/i18n/config'; import { SUPPORTED_CHAINS, getChainIdFromSlug, getChainName, getChainSlug } from 'lib/utils/chains'; import { generateOgImage, loadDataUrl } from 'lib/utils/og'; @@ -13,8 +14,8 @@ interface Props { }; } -export const dynamic = 'error'; -export const dynamicParams = false; +export const dynamic = SKIP_OG_IMAGES ? 'error' : 'force-dynamic'; +export const dynamicParams = SKIP_OG_IMAGES; export const generateStaticParams = () => { const slugs = SUPPORTED_CHAINS.map(getChainSlug); diff --git a/lib/constants.ts b/lib/constants.ts index d8705f23..9395c763 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -31,3 +31,5 @@ export const HARPIE_API_KEY = process.env.HARPIE_API_KEY ?? process.env.NEXT_PUB export const WEBACY_API_KEY = process.env.WEBACY_API_KEY ?? process.env.NEXT_PUBLIC_WEBACY_API_KEY; export const NEFTURE_API_KEY = process.env.NEFTURE_API_KEY ?? process.env.NEXT_PUBLIC_NEFTURE_API_KEY; export const RESERVOIR_API_KEY = process.env.RESERVOIR_API_KEY ?? process.env.NEXT_PUBLIC_RESERVOIR_API_KEY; + +export const SKIP_OG_IMAGES = process.env.SKIP_OG_IMAGES === 'true'; diff --git a/lib/utils/og.tsx b/lib/utils/og.tsx index 71b202b6..66401c42 100644 --- a/lib/utils/og.tsx +++ b/lib/utils/og.tsx @@ -24,18 +24,6 @@ export const generateOgImage = ({ title, background }: OgImageProps) => { const width = 1200; const height = 630; - // If SKIP_OG_IMAGES is true, return a placeholder image instead of generating one dynamically. - // This significantly speeds up builds during emergency patches by skipping resource-intensive OG image generation. - const SKIP_OG_IMAGES = process.env.SKIP_OG_IMAGES === 'true'; - if (SKIP_OG_IMAGES) { - return new Response(loadFile('public/assets/images/opengraph-image.jpg'), { - headers: { - 'Content-Type': 'image/jpeg', - 'Cache-Control': 'public, max-age=31536000, immutable', - }, - }); - } - const icon = loadDataUrl('public/assets/images/revoke-icon-orange-black.svg', 'image/svg+xml'); const response = (