Skip to content

Commit

Permalink
Add new components for slug not found and page rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
FoggyMtnDrifter committed Mar 8, 2024
1 parent e1aa223 commit 3e3b23c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/[locale]/resources/[slug]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useTranslations } from "next-intl";

export default function SlugNotFound() {
const t = useTranslations("global.notFound");

return (
<div className="py-24 sm:py-32">
<div className="mx-auto max-w-3xl text-base leading-7">
<h1 className="mt-2 text-3xl font-bold tracking-tight sm:text-4xl mb-12 text-center font-display">
{t("title")}
</h1>
<div className="prose dark:prose-invert prose-headings:font-display prose-a:text-primary prose-pre:bg-muted prose-pre:py-3 prose-pre:px-4 prose-pre:rounded prose-img:rounded-md max-w-none text-center">
{t("description")}
</div>
</div>
</div>
);
}
56 changes: 56 additions & 0 deletions app/[locale]/resources/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { checkIfSlugIsValid, getContentData } from "@/lib/resourcesPages";
import { notFound } from "next/navigation";

export type Params = {
slug: string;
};

export type Props = {
params: Params;
};

export type pageData = {
title: string;
description: string;
contentHtml: string;
};

export async function generateMetadata({ params }: Props) {
const slug = params.slug;

if (!(await checkIfSlugIsValid(slug))) {
return {
title: "Not Found",
};
}

const pageData: pageData = await getContentData(slug);

return {
title: `${pageData.title} - Rocky Linux`,
};
}

export default async function Page({ params }: Props) {
const slug = params.slug;

if (!(await checkIfSlugIsValid(slug))) {
notFound();
}

const pageData: pageData = await getContentData(slug);

return (
<div className="py-24 sm:py-32">
<div className="mx-auto max-w-3xl text-base leading-7">
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl mb-12 text-center font-display">
{pageData.title}
</h1>
<div
className="prose dark:prose-invert prose-headings:font-display prose-a:text-primary prose-pre:bg-muted prose-pre:py-3 prose-pre:px-4 prose-pre:rounded prose-img:rounded-md max-w-none mb-12"
dangerouslySetInnerHTML={{ __html: pageData.contentHtml }}
/>
</div>
</div>
);
}

0 comments on commit 3e3b23c

Please sign in to comment.