update scripts to fix a few bugs
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const walk = require('walk-sync')
|
const walk = require('walk-sync')
|
||||||
|
const stripHtmlComments = require('strip-html-comments')
|
||||||
const languages = require('../../lib/languages')
|
const languages = require('../../lib/languages')
|
||||||
const frontmatter = require('../../lib/read-frontmatter')
|
const frontmatter = require('../../lib/read-frontmatter')
|
||||||
const addRedirectToFrontmatter = require('../../lib/redirects/add-redirect-to-frontmatter')
|
const addRedirectToFrontmatter = require('../../lib/redirects/add-redirect-to-frontmatter')
|
||||||
@@ -26,6 +27,10 @@ const categoryIndexFiles = fullDirectoryPaths.map(fullDirectoryPath => walk(full
|
|||||||
categoryIndexFiles.forEach(categoryIndexFile => {
|
categoryIndexFiles.forEach(categoryIndexFile => {
|
||||||
let categoryIndexContent = fs.readFileSync(categoryIndexFile, 'utf8')
|
let categoryIndexContent = fs.readFileSync(categoryIndexFile, 'utf8')
|
||||||
|
|
||||||
|
if (categoryIndexFile.endsWith('github/getting-started-with-github/index.md')) {
|
||||||
|
categoryIndexContent = stripHtmlComments(categoryIndexContent.replace(/\n<!--/g, '<!--'))
|
||||||
|
}
|
||||||
|
|
||||||
// find array of TOC link strings
|
// find array of TOC link strings
|
||||||
const rawItems = categoryIndexContent.match(linksArray)
|
const rawItems = categoryIndexContent.match(linksArray)
|
||||||
if (!rawItems || !rawItems[0].includes('topic_link_in_list')) return
|
if (!rawItems || !rawItems[0].includes('topic_link_in_list')) return
|
||||||
|
|||||||
@@ -72,8 +72,14 @@ indexFiles
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the Table of Contents section and leave any custom content before it.
|
// Remove the Table of Contents section and leave any body text before it.
|
||||||
const newContent = content.replace(/^#*? Table of contents[\s\S]*/im, '')
|
const newContent = content
|
||||||
|
.replace(/^#*? Table of contents[\s\S]*/im, '')
|
||||||
|
.replace('<div hidden>', '')
|
||||||
|
.replace(linksArray, '')
|
||||||
|
.split('\n')
|
||||||
|
.filter(line => /\S/.test(line))
|
||||||
|
.join('\n')
|
||||||
|
|
||||||
// Index files should no longer have body content, so we write an empty string
|
// Index files should no longer have body content, so we write an empty string
|
||||||
fs.writeFileSync(indexFile, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))
|
fs.writeFileSync(indexFile, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))
|
||||||
|
|||||||
Reference in New Issue
Block a user