mirror of
https://github.com/sass/sass.git
synced 2024-09-21 10:37:22 +00:00
Add TOCs to files with a TOC header but no body
This commit is contained in:
parent
c08d3bc3c3
commit
826fe7d78d
@ -5,11 +5,25 @@ toc.files.forEach(function (file) {
|
||||
var markdown = fs.readFileSync(file).toString()
|
||||
|
||||
var currentToc = toc.getCurrent(markdown)
|
||||
if (currentToc == null) return
|
||||
if (currentToc == null) {
|
||||
var match = markdown.match('## Table of Contents\n\n')
|
||||
if (!match) return
|
||||
|
||||
var tocLocation = match.index + match[0].length
|
||||
|
||||
// If there's an empty TOC, fill it in.
|
||||
fs.writeFileSync(
|
||||
file,
|
||||
markdown.substring(0, tocLocation) +
|
||||
toc.generate(markdown) + '\n\n' +
|
||||
markdown.substring(tocLocation))
|
||||
console.log(`Added TOC to ${file}`)
|
||||
return
|
||||
}
|
||||
|
||||
var generatedToc = toc.generate(markdown)
|
||||
if (currentToc === generatedToc) return
|
||||
|
||||
fs.writeFileSync(file, markdown.replace(currentToc, generatedToc))
|
||||
console.log(`Updated ${file}`)
|
||||
console.log(`Updated TOC in ${file}`)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user