Skip to content

Commit fe02505

Browse files
author
abrulic
committed
restored previous helper functions
1 parent 4aaf5a3 commit fe02505

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

content-collections.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const cleanSlug = (p: string) =>
5050
const toPosix = (s: string) => {
5151
return posix.normalize(s.replace(/\\/g, "/"))
5252
}
53+
const stripExt = (s: string) => s.replace(/\.(md|mdx)$/i, "")
54+
const stripTrailingIndex = (s: string) => s.replace(/\/index$/i, "")
5355

5456
/*
5557
* This collection defines a documentation section shown in the sidebar of the package documentation.
@@ -63,7 +65,7 @@ const section = defineCollection({
6365
include: "**/index.md",
6466
schema: sectionSchema,
6567
transform: (document) => {
66-
const slug = cleanSlug(document._meta.path)
68+
const slug = stripTrailingIndex(cleanSlug(document._meta.path))
6769
return { ...document, slug }
6870
},
6971
})
@@ -79,7 +81,8 @@ const page = defineCollection({
7981
include: "**/**/*.mdx",
8082
schema: pageSchema,
8183
transform: async (document, context) => {
82-
const slug = cleanSlug(document._meta.path)
84+
const cleanedSlug = cleanSlug(document._meta.path)
85+
const slug = stripExt(cleanedSlug)
8386
const content = await compileMDX(context, document, { rehypePlugins: [rehypeSlug] })
8487
const rawMdx = document.content.replace(/^---\s*[\r\n](.*?|\r|\n)---/, "").trim()
8588

0 commit comments

Comments
 (0)