mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 21:29:08 +03:00
Test for both md and mdx
This commit is contained in:
1 parent
006656b8aa
commit
ead80901a0
1 file changed
+16
-1
@@ -5,9 +5,24 @@ import matter from 'gray-matter'
|
||||
const docsDirectory = process.cwd()
|
||||
|
||||
export function getDocsBySlug(slug: string) {
|
||||
console.log('getDocsBySlug', { slug })
|
||||
const realSlug = slug.replace(/\.mdx$/, '')
|
||||
let fullPath = join(docsDirectory, `${realSlug}.mdx`)
|
||||
|
||||
// files can either be .md or .mdx
|
||||
// we need to check which one exists
|
||||
let fullPath
|
||||
let fullPathMD = join(docsDirectory, `${realSlug}.md`)
|
||||
let fullPathMDX = join(docsDirectory, `${realSlug}.mdx`)
|
||||
|
||||
if (fs.existsSync(fullPathMD)) {
|
||||
fullPath = fullPathMD
|
||||
}
|
||||
|
||||
if (fs.existsSync(fullPathMDX)) {
|
||||
fullPath = fullPathMDX
|
||||
}
|
||||
|
||||
// if no match, 404
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
console.log(`\nfile ${fullPath} not found, redirect to 404\n`)
|
||||
fullPath = join(docsDirectory, 'docs/404.mdx')
|
||||
|
||||
Reference in new issue
Block a user