Skip to content

Commit 5e2a1b5

Browse files
committed
update scripts to fix a few bugs
1 parent ebc2c11 commit 5e2a1b5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

script/content-migrations/remove-map-topics.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const fs = require('fs')
44
const path = require('path')
55
const walk = require('walk-sync')
6+
const stripHtmlComments = require('strip-html-comments')
67
const languages = require('../../lib/languages')
78
const frontmatter = require('../../lib/read-frontmatter')
89
const addRedirectToFrontmatter = require('../../lib/redirects/add-redirect-to-frontmatter')
@@ -26,6 +27,10 @@ const categoryIndexFiles = fullDirectoryPaths.map(fullDirectoryPath => walk(full
2627
categoryIndexFiles.forEach(categoryIndexFile => {
2728
let categoryIndexContent = fs.readFileSync(categoryIndexFile, 'utf8')
2829

30+
if (categoryIndexFile.endsWith('github/getting-started-with-github/index.md')) {
31+
categoryIndexContent = stripHtmlComments(categoryIndexContent.replace(/\n<!--/g, '<!--'))
32+
}
33+
2934
// find array of TOC link strings
3035
const rawItems = categoryIndexContent.match(linksArray)
3136
if (!rawItems || !rawItems[0].includes('topic_link_in_list')) return

script/content-migrations/update-tocs.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ indexFiles
7272
]
7373
}
7474

75-
// Remove the Table of Contents section and leave any custom content before it.
76-
const newContent = content.replace(/^#*? Table of contents[\s\S]*/im, '')
75+
// Remove the Table of Contents section and leave any body text before it.
76+
const newContent = content
77+
.replace(/^#*? Table of contents[\s\S]*/im, '')
78+
.replace('<div hidden>', '')
79+
.replace(linksArray, '')
80+
.split('\n')
81+
.filter(line => /\S/.test(line))
82+
.join('\n')
7783

7884
// Index files should no longer have body content, so we write an empty string
7985
fs.writeFileSync(indexFile, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))

0 commit comments

Comments
 (0)