Skip to content

Commit 056b3d9

Browse files
committed
address Copilot review feedback
1 parent e2222e5 commit 056b3d9

7 files changed

Lines changed: 68 additions & 55 deletions

File tree

src/app/(core)/(static)/newsletter/feed.xml/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getNewsletterIssueImageUrl } from "@/utils/storage";
66
import { defaultLocale, normaliseLocale } from "@/i18n/config";
77
import { getTranslations } from "next-intl/server";
88

9-
export const dynamic = "force-dynamic";
9+
export const revalidate = 3600;
1010

1111
export async function GET(request: Request) {
1212
const requestUrl = new URL(request.url);
@@ -51,6 +51,7 @@ export async function GET(request: Request) {
5151
return new Response(feed.rss2(), {
5252
headers: {
5353
"Content-Type": "application/rss+xml",
54+
"Cache-Control": "public, s-maxage=3600, stale-while-revalidate=86400",
5455
},
5556
});
5657
}

src/app/actions.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,13 @@ import {
1616
} from "@/utils/utils";
1717
import { getUserLocale, setUserLocale } from "@/i18n/services/locale";
1818
import { resolveAuthLocale } from "@/utils/authRedirects";
19+
import { isMissingPreferredLocaleColumn } from "@/utils/postgrest";
1920
import { normaliseLocale } from "@/i18n/config";
2021
import { revalidatePath } from "next/cache";
2122
import { headers } from "next/headers";
2223
import { redirect } from "next/navigation";
2324
import { getTranslations } from "next-intl/server";
2425

25-
function isMissingPreferredLocaleColumn(error: {
26-
code?: string | null;
27-
message?: string | null;
28-
}) {
29-
return (
30-
error.code === "PGRST204" && /preferred_locale/i.test(error.message ?? "")
31-
);
32-
}
33-
3426
function translateFirstNameFieldError(
3527
t: Awaited<ReturnType<typeof getTranslations>>,
3628
code?: FirstNameErrorCode

src/app/layout.tsx

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NextIntlClientProvider } from "next-intl";
2-
import { getLocale, getTranslations } from "next-intl/server";
2+
import { getLocale } from "next-intl/server";
33
import { Metadata } from "next";
44
import { siteConfig } from "@/config/site";
55
import { getStaticFontUrl, usesHostedStaticAssets } from "@/utils/storage";
@@ -184,37 +184,31 @@ const Body = styled("body")(({ theme }) => ({
184184
backgroundColor: theme.colors.background.sunk,
185185
}));
186186

187-
export async function generateMetadata(): Promise<Metadata> {
188-
const locale = await getLocale();
189-
const t = await getTranslations();
190-
const description = t("Index.subtitle");
191-
192-
return {
193-
metadataBase: new URL(siteConfig.url),
194-
title: {
195-
default: siteConfig.name,
196-
template: `%s · ${siteConfig.name}`,
197-
},
198-
description,
199-
keywords: [...siteConfig.meta.keywords],
200-
openGraph: {
201-
title: siteConfig.name,
202-
type: "website",
203-
description,
204-
siteName: siteConfig.name,
187+
export const metadata: Metadata = {
188+
metadataBase: new URL(siteConfig.url),
189+
title: {
190+
default: siteConfig.name,
191+
template: `%s · ${siteConfig.name}`,
192+
},
193+
description: siteConfig.description,
194+
keywords: [...siteConfig.meta.keywords],
195+
openGraph: {
196+
title: siteConfig.name,
197+
type: "website",
198+
description: siteConfig.description,
199+
siteName: siteConfig.name,
200+
},
201+
alternates: {
202+
types: {
203+
"application/rss+xml": [
204+
{
205+
title: `${siteConfig.name}: Newsletter`,
206+
url: `${siteConfig.url}/newsletter/feed.xml`,
207+
},
208+
],
205209
},
206-
alternates: {
207-
types: {
208-
"application/rss+xml": [
209-
{
210-
title: `${siteConfig.name}: ${t("Newsletter.title")}`,
211-
url: `${siteConfig.url}/newsletter/feed.xml?locale=${locale}`,
212-
},
213-
],
214-
},
215-
},
216-
};
217-
}
210+
},
211+
};
218212

219213
export default async function RootLayout({
220214
children,

src/i18n/services/locale.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { cookies, headers } from "next/headers";
44
import { createClient } from "@/utils/supabase/server";
5+
import { isMissingPreferredLocaleColumn } from "@/utils/postgrest";
56
import {
67
defaultLocale,
78
type Locale,
@@ -11,15 +12,6 @@ import {
1112
parseAcceptLanguageHeader,
1213
} from "@/i18n/config";
1314

14-
function isMissingPreferredLocaleColumn(error: {
15-
code?: string | null;
16-
message?: string | null;
17-
}) {
18-
return (
19-
error.code === "PGRST204" && /preferred_locale/i.test(error.message ?? "")
20-
);
21-
}
22-
2315
export async function getUserLocale() {
2416
const supabase = await createClient();
2517
const {

src/lib/content/handlers/newsletter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const getNewsletterIssueMetadata = cache(
3939
},
4040
resolvedLocale,
4141
"publishDate",
42-
true // publishDate is required for legal pages
42+
true // publishDate is required for newsletter issues
4343
);
4444
}
4545

src/lib/content/utils.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Shared utils between all Markdown collections, like newsletter issues and legal pages
22
// https://www.notion.so/peels/Markdown-Pages-20bb37e1678f806a9649c3c658ab6258?source=copy_link
33

4-
import { readdir } from "fs/promises";
4+
import { access, readdir } from "fs/promises";
55
import type { Dirent } from "fs";
66
import { join } from "path";
77
import { defaultLocale, type Locale, normaliseLocale } from "@/i18n/config";
@@ -27,13 +27,31 @@ export function formatContentDate(dateString: string, locale: Locale) {
2727
}).format(new Date(dateString));
2828
}
2929

30+
async function doesContentFileExist(contentPath: string) {
31+
try {
32+
await access(contentPath);
33+
return true;
34+
} catch {
35+
return false;
36+
}
37+
}
38+
3039
export async function importLocalizedContentModule(
3140
contentType: "newsletter" | "legal",
3241
slug: string,
3342
locale: Locale
3443
) {
3544
if (locale !== defaultLocale) {
36-
try {
45+
const localisedContentPath = join(
46+
process.cwd(),
47+
"src",
48+
"content",
49+
contentType,
50+
locale,
51+
`${slug}.mdx`
52+
);
53+
54+
if (await doesContentFileExist(localisedContentPath)) {
3755
const file = await import(
3856
`@/content/${contentType}/${locale}/${slug}.mdx`
3957
);
@@ -42,8 +60,6 @@ export async function importLocalizedContentModule(
4260
locale,
4361
isFallback: false,
4462
};
45-
} catch (_error) {
46-
// Fall through to the default English content.
4763
}
4864
}
4965

src/utils/postgrest.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type PostgrestLikeError = {
2+
code?: string | null;
3+
message?: string | null;
4+
};
5+
6+
export function isMissingPostgrestColumn(
7+
error: PostgrestLikeError,
8+
columnName: string
9+
) {
10+
return (
11+
error.code === "PGRST204" &&
12+
new RegExp(columnName, "i").test(error.message ?? "")
13+
);
14+
}
15+
16+
export function isMissingPreferredLocaleColumn(error: PostgrestLikeError) {
17+
return isMissingPostgrestColumn(error, "preferred_locale");
18+
}

0 commit comments

Comments
 (0)