Files
supabase/apps/docs/lib/mdx/generateRefMarkdown.tsx
T
Tyler eb9f0240cb docs: Remove error codes section from Flutter, Swift, and Python reference docs. (#28334)
* exclude dart, python, and swift from error codes menu

* Update the error code doc to be client lib agnostic

* run formatter

* Add a filter to filter out section items

* Update apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx

* docs: move error codes table in a separate component

* Add auth error codes section for kotlin
2024-08-06 11:41:10 +09:00

69 lines
2.0 KiB
TypeScript

import fs from 'fs'
import { CodeHikeConfig, remarkCodeHike } from '@code-hike/mdx'
import codeHikeTheme from 'config/code-hike.theme.json' assert { type: 'json' }
import matter from 'gray-matter'
import { serialize } from 'next-mdx-remote/serialize'
import remarkGfm from 'remark-gfm'
import type { ICommonMarkdown } from '~/components/reference/Reference.types'
async function generateRefMarkdown(sections: ICommonMarkdown[], slug: string) {
let markdownContent = []
/**
* Read all the markdown files that might have
* - custom text
* - call outs
* - important notes regarding implementation
*/
await Promise.all(
sections.map(async (section) => {
const pathName = `docs/ref${slug}/${section.id}.mdx`
function checkFileExists(x) {
if (fs.existsSync(x)) {
return true
} else {
return false
}
}
const markdownExists = checkFileExists(pathName)
if (!markdownExists) return null
const fileContents = markdownExists ? fs.readFileSync(pathName, 'utf8') : ''
const { data, content } = matter(fileContents)
const codeHikeOptions: CodeHikeConfig = {
theme: codeHikeTheme,
lineNumbers: true,
showCopyButton: true,
skipLanguages: [],
autoImport: false,
}
markdownContent.push({
id: section.id,
title: section.title,
meta: data,
// introPage: introPages.includes(x),
content: content
? await serialize(content ?? '', {
// MDX's available options, see the MDX docs for more info.
// https://mdxjs.com/packages/mdx/#compilefile-options
mdxOptions: {
useDynamicImport: true,
remarkPlugins: [remarkGfm, [remarkCodeHike, codeHikeOptions]],
},
// Indicates whether or not to parse the frontmatter from the mdx source
})
: null,
})
})
)
return markdownContent
}
export default generateRefMarkdown