docs(build): optimize the regular (#11812)

* docs(build): optimize the regular

* chore: rename firstSubheader to firstHeader

* docs(build): optimize the regular
This commit is contained in:
qiang 2023-03-10 14:54:42 +08:00 committed by GitHub
parent b38607f53b
commit a842504164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 firstHeader = code.search(/\n#{1,6}\s.+/)
const sliceIndex =
firstHeader < 0
? frontmatterEnds < 0
? 0
: frontmatterEnds + 4
: firstHeader
if (headers.length > 0)
code =