docs: error when frontmatter does not exist (#10561)

This commit is contained in:
洪布斯 2023-03-01 14:23:44 +08:00 committed by GitHub
parent a30ae9d103
commit c88c6cdb8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,9 +48,9 @@ export function MarkdownTransform(): Plugin {
}
const combineScriptSetup = (codes: string[]) =>
`\n<script setup>
`<script setup>
${codes.join('\n')}
</script>
</script>\n
`
const combineMarkdown = (
@ -58,9 +58,14 @@ const combineMarkdown = (
headers: string[],
footers: string[]
) => {
const frontmatterEnds = code.indexOf('---\n\n') + 4
const firstSubheader = code.search(/\n## \w/)
const sliceIndex = firstSubheader < 0 ? frontmatterEnds : firstSubheader
const frontmatterEnds = code.indexOf('---\n\n')
const firstSubheader = code.search(/## \w/)
const sliceIndex =
firstSubheader < 0
? frontmatterEnds < 0
? 0
: frontmatterEnds + 5
: firstSubheader
if (headers.length > 0)
code =