Skip to content
Open
Show file tree
Hide file tree
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
94 changes: 73 additions & 21 deletions src/app/[locale]/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export default async function Page(props: {
// === STRICTER getHeroImage (prevents empty src/darkSrc) ===
const getHeroImage = (slugSegment: string) => {
const src = getBanner(slugSegment) || "";
const darkSrc = getBanner(`${slugSegment}-dark`) || getBanner(slugSegment) || "";
const darkSrc =
getBanner(`${slugSegment}-dark`) || getBanner(slugSegment) || "";

if (!src) return undefined;

Expand Down Expand Up @@ -428,7 +429,14 @@ export default async function Page(props: {
<MdxContainer
hasSideMenu={showSideMenu}
sideMenu={
showSideMenu ? <SideMenu folder={slug[0]} roots={roots} titles={menuTitles} enTitles={enMenuTitles} /> : null
showSideMenu ? (
<SideMenu
folder={slug[0]}
roots={roots}
titles={menuTitles}
enTitles={enMenuTitles}
/>
) : null
}
roots={roots}
heroImage={{ src: imgUrl, darkSrc: imgUrlDark }}
Expand All @@ -446,32 +454,76 @@ export default async function Page(props: {
);
}

const serializedSource = await serialize(normalizeMdx(processedMarkdown), {
mdxOptions: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
[
rehypeRaw,
{
passThrough: [
"mdxJsxFlowElement",
"mdxFlowExpression",
"mdxJsxTextElement",
"mdxTextExpression",
],
},
let serializedSource;
try {
serializedSource = await serialize(normalizeMdx(processedMarkdown), {
mdxOptions: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
[
rehypeRaw,
{
passThrough: [
"mdxJsxFlowElement",
"mdxFlowExpression",
"mdxJsxTextElement",
"mdxTextExpression",
],
},
],
],
],
},
});
},
});
} catch (e) {
// The content repo is community-edited; a single malformed MDX/JSX block
// (e.g. an unclosed tag) would otherwise crash the whole page with a
// server error. Fail soft instead: log for diagnosis and show the same
// "browse the sidebar" shell used for missing content.
console.error(`Failed to compile MDX for ${contentUrl}: `, e);
return (
<MdxContainer
hasSideMenu={showSideMenu}
sideMenu={
showSideMenu ? (
<SideMenu
folder={slug[0]}
roots={roots}
titles={menuTitles}
enTitles={enMenuTitles}
/>
) : null
}
roots={roots}
heroImage={{ src: imgUrl, darkSrc: imgUrlDark }}
>
<div className="px-6 py-12 text-center">
<h1 className="text-5xl font-bold mb-6 capitalize">
{slug[0].replace(/-/g, " ")}
</h1>
<p className="text-xl text-muted-foreground">
This page has a content formatting issue and couldn&apos;t be
displayed. Please check back soon, or browse other articles using
the sidebar 👈
</p>
</div>
</MdxContainer>
);
}

const heroImage = getHeroImage(slug[0]);

return (
<MdxContainer
hasSideMenu={showSideMenu}
sideMenu={
showSideMenu ? <SideMenu folder={slug[0]} roots={roots} titles={menuTitles} enTitles={enMenuTitles} /> : null
showSideMenu ? (
<SideMenu
folder={slug[0]}
roots={roots}
titles={menuTitles}
enTitles={enMenuTitles}
/>
) : null
}
roots={roots}
{...(heroImage ? { heroImage } : {})}
Expand All @@ -495,4 +547,4 @@ export default async function Page(props: {
);
}

export const dynamic = "force-dynamic";
export const dynamic = "force-dynamic";
Loading