MCPcopy Create free account
hub / github.com/github/docs / updateMdHeaders

Function updateMdHeaders

script/content-migrations/add_mini_toc_frontmatter.js:18–43  ·  view source on GitHub ↗
(dir)

Source from the content-addressed store, hash-verified

16const re = /^---\n/gm
17
18async function updateMdHeaders(dir) {
19 walk(dir, { includeBasePath: true, directories: false })
20 .filter(
21 (file) =>
22 !file.endsWith('README.md') &&
23 !file.endsWith('index.md') &&
24 file.includes('content/rest/reference')
25 )
26 .forEach((file) => {
27 fs.readFile(file, 'utf8', (err, data) => {
28 if (err) return console.error(err)
29 const matchHeader = data.match(re)[1]
30 let result
31 let t = 0
32 if (matchHeader) {
33 result = data.replace(re, function (match) {
34 t++
35 return t === 2 ? 'miniTocMaxHeadingLevel: 3\n---\n' : match
36 })
37 }
38 fs.writeFile(file, result, 'utf8', function (err) {
39 if (err) return console.log(err)
40 })
41 })
42 })
43}
44
45async function main() {
46 await updateMdHeaders(path.join(__dirname, '../../content'))

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected