| 16 | const re = /^---\n/gm |
| 17 | |
| 18 | async 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 | |
| 45 | async function main() { |
| 46 | await updateMdHeaders(path.join(__dirname, '../../content')) |