Skip to content

Commit a8588d8

Browse files
committed
fix duplication heading
1 parent 0a2839e commit a8588d8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/stories/[slug]/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import Footer from "@/components/footer";
66
import { canela_regu } from "@/lib/fonts";
77
import { formatDate } from "../utils";
88

9+
// Remove a leading H1 and an immediate horizontal rule (---) from MDX content
10+
function stripTopHeadingAndHr(mdx: string) {
11+
return mdx
12+
.replace(/^\s*# [^\n]*\n(?:\s*\n)*/m, "") // strip leading H1 and following blank lines
13+
.replace(/^\s*---\s*\n(?:\s*\n)*/m, ""); // strip immediate hr and following blank lines if present
14+
}
15+
916
export async function generateStaticParams() {
1017
let posts = getStoriesPosts();
1118

@@ -63,6 +70,8 @@ export default function StoriesPost({ params }) {
6370
notFound();
6471
}
6572

73+
const sanitizedContent = stripTopHeadingAndHr(post.content);
74+
6675
return (
6776
<div className="min-h-screen bg-gradient-to-b">
6877
<Header />
@@ -92,7 +101,7 @@ export default function StoriesPost({ params }) {
92101
)}
93102

94103
<div className="prose prose-lg max-w-none">
95-
<CustomMDX source={post.content} />
104+
<CustomMDX source={sanitizedContent} />
96105
</div>
97106
</article>
98107
</div>

0 commit comments

Comments
 (0)