Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions app/[locale]/stories/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { pick } from "lodash"
import type { Metadata } from "next"
import { getMessages, setRequestLocale } from "next-intl/server"
import { notFound } from "next/navigation"
import {
getMessages,
getTranslations,
setRequestLocale,
} from "next-intl/server"

import I18nProvider from "@/components/I18nProvider"
import mdComponents from "@/components/MdComponents"
Expand All @@ -20,6 +25,11 @@ const StoryPage = async (props: {
}) => {
const { locale, slug } = await props.params

// Guard against non-existent story slugs (e.g. crawler probes) so they 404
// instead of throwing an ENOENT when the markdown file is read.
const slugs = await getStorySlugs()
if (!slugs.includes(slug)) notFound()

setRequestLocale(locale)

// Story content lives at public/content/stories/{slug}/index.md, so it slots
Expand Down Expand Up @@ -89,10 +99,20 @@ export async function generateMetadata(props: {
}): Promise<Metadata> {
const { locale, slug } = await props.params

return await getMdMetadata({
locale,
slug: ["stories", slug],
})
try {
return await getMdMetadata({
locale,
slug: ["stories", slug],
})
} catch {
// Return basic metadata for invalid paths (mirrors the shared [...slug] route)
const t = await getTranslations("common")

return {
title: t("page-not-found"),
description: t("page-not-found-description"),
}
}
}

export default StoryPage
Loading