diff --git a/app/[locale]/og.jpg/blog/[...slug]/route.tsx b/app/[locale]/og.jpg/blog/[...slug]/route.tsx index 6ed31ca76..8873bdd36 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,13 +14,15 @@ 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'); - return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + const slugs = getAllContentSlugs('blog'); + return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); + }; export async function GET(req: Request, { params }: Props) { const { meta } = readAndParseContentFile(params.slug, params.locale, 'blog')!; diff --git a/app/[locale]/og.jpg/blog/route.tsx b/app/[locale]/og.jpg/blog/route.tsx index 6b5668b4d..73909f852 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,12 +12,14 @@ 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 })); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + return locales.map((locale) => ({ locale })); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.locale }); diff --git a/app/[locale]/og.jpg/exploits/route.tsx b/app/[locale]/og.jpg/exploits/route.tsx index 2f4335b7e..91d28b84c 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,12 +12,14 @@ 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 })); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + return locales.map((locale) => ({ locale })); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.locale }); diff --git a/app/[locale]/og.jpg/learn/[...slug]/route.tsx b/app/[locale]/og.jpg/learn/[...slug]/route.tsx index c1818894d..f60739c05 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,13 +14,15 @@ 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'); - return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + const slugs = getAllContentSlugs('learn'); + return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); + }; export async function GET(req: Request, { params }: Props) { const { meta } = readAndParseContentFile(params.slug, params.locale, 'learn')!; diff --git a/app/[locale]/og.jpg/learn/[category]/route.tsx b/app/[locale]/og.jpg/learn/[category]/route.tsx index a02accd6a..4d494fd86 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,13 +14,15 @@ 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(); - return locales.flatMap((locale) => categorySlugs.map((category) => ({ locale, category }))); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + const categorySlugs = getAllLearnCategories(); + return locales.flatMap((locale) => categorySlugs.map((category) => ({ locale, category }))); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.locale }); diff --git a/app/[locale]/og.jpg/learn/faq/route.tsx b/app/[locale]/og.jpg/learn/faq/route.tsx index 8d0d622da..1850bf742 100644 --- a/app/[locale]/og.jpg/learn/faq/route.tsx +++ b/app/[locale]/og.jpg/learn/faq/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,12 +12,14 @@ 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 })); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + return locales.map((locale) => ({ locale })); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.locale }); diff --git a/app/[locale]/og.jpg/learn/route.tsx b/app/[locale]/og.jpg/learn/route.tsx index 00f5d5755..54bef36b2 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,12 +12,14 @@ 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 })); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + return locales.map((locale) => ({ locale })); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.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 2c2df1b02..120ca4122 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,13 +14,15 @@ 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); - return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + const slugs = SUPPORTED_CHAINS.map(getChainSlug); + return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.locale }); 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 2f03ec165..4eadc7aa2 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,12 +12,14 @@ 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 })); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + return locales.map((locale) => ({ locale })); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.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 f8ca07157..a605647c3 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,13 +14,15 @@ 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); - return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); -}; +export const generateStaticParams = SKIP_OG_IMAGES + ? undefined + : () => { + const slugs = SUPPORTED_CHAINS.map(getChainSlug); + return locales.flatMap((locale) => slugs.map((slug) => ({ locale, slug }))); + }; export async function GET(req: Request, { params }: Props) { const t = await getTranslations({ locale: params.locale }); diff --git a/lib/constants.ts b/lib/constants.ts index d8705f239..9395c7634 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 71b202b6b..66401c420 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 = ( diff --git a/next.config.js b/next.config.js index 82518b492..79b62e4c9 100644 --- a/next.config.js +++ b/next.config.js @@ -47,6 +47,11 @@ const nextConfig = { config.externals.push('pino-pretty'); return config; }, + experimental: { + outputFileTracingIncludes: { + '/**': ['public/**'], + }, + }, }; module.exports = nextConfig;