This repository has been archived on 2026-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
site-2025/src/app/[locale]/pages/[slug]/page.tsx
Dariusz Niemczyk 9fc91d9480
Some checks failed
/ deploy (push) Failing after 40s
feat: additionally sanitize slugs
2025-02-15 01:17:49 +01:00

35 lines
730 B
TypeScript

import { getLocale, Lang } from "@/i18n/locales"
import { notFound } from "next/navigation"
export default async function Page({
params,
}: {
params: Promise<{ slug: string, locale: Lang }>
}) {
const { slug, locale } = await params
const currentLocale = getLocale(locale)
const isReallyProperSlug = /^[a-zA-Z0-9_-]+$/.test(slug)
if (!isReallyProperSlug) {
notFound()
}
try {
const path = `@/pages/${currentLocale}/${slug}.mdx`
const pagemodule = await import(path)
const Post = pagemodule.default
return <Post />
} catch (error) {
console.log(error)
notFound()
}
}
export function generateStaticParams() {
return [{ slug: 'privacy' }]
}
export const dynamicParams = false