Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Dec 16, 2024
1 parent 9390685 commit b1da0b8
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 67 deletions.
15 changes: 9 additions & 6 deletions app/[locale]/og.jpg/blog/[...slug]/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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')!;
Expand Down
13 changes: 8 additions & 5 deletions app/[locale]/og.jpg/blog/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
13 changes: 8 additions & 5 deletions app/[locale]/og.jpg/exploits/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
15 changes: 9 additions & 6 deletions app/[locale]/og.jpg/learn/[...slug]/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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')!;
Expand Down
15 changes: 9 additions & 6 deletions app/[locale]/og.jpg/learn/[category]/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
13 changes: 8 additions & 5 deletions app/[locale]/og.jpg/learn/faq/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
13 changes: 8 additions & 5 deletions app/[locale]/og.jpg/learn/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
15 changes: 9 additions & 6 deletions app/[locale]/og.jpg/learn/wallets/add-network/[slug]/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
13 changes: 8 additions & 5 deletions app/[locale]/og.jpg/learn/wallets/add-network/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
15 changes: 9 additions & 6 deletions app/[locale]/og.jpg/token-approval-checker/[slug]/route.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 });
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
12 changes: 0 additions & 12 deletions lib/utils/og.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
5 changes: 5 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const nextConfig = {
config.externals.push('pino-pretty');
return config;
},
experimental: {
outputFileTracingIncludes: {
'/**': ['public/**'],
},
},
};

module.exports = nextConfig;
Expand Down

0 comments on commit b1da0b8

Please sign in to comment.