MCPcopy Index your code
hub / github.com/github/docs / main

Function main

script/enterprise-server-deprecations/remove-version-markup.js:58–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56main()
57
58async function main() {
59 for (const file of allFiles) {
60 const oldContents = fs.readFileSync(file, 'utf8')
61 const { content, data } = frontmatter(oldContents)
62
63 // update frontmatter versions prop
64 removeDeprecatedFrontmatter(file, data.versions, release, nextOldestRelease)
65
66 // update liquid statements in content and data
67 const newContent = removeLiquidStatements(content, release, nextOldestRelease, file)
68
69 // update liquid statements in content frontmatter (like intro and title)
70 for (const key in data) {
71 const value = data[key]
72 if (typeof value === 'string' && value.includes('{% ifversion')) {
73 const newValue = removeLiquidStatements(value, release, nextOldestRelease, file)
74 data[key] = newValue
75 }
76 }
77
78 // make sure any intro fields that exist and are empty return an empty string, not null
79 if (typeof data.intro !== 'undefined' && !data.intro) {
80 data.intro = ''
81 }
82
83 // put it all back together
84 const newContents = frontmatter.stringify(newContent, data, { lineWidth: 10000 })
85
86 // if the content file is now empty, remove it
87 if (newContents.replace(/\s/g, '').length === 0) {
88 fs.unlinkSync(file)
89 continue
90 }
91
92 fs.writeFileSync(file, newContents)
93 }
94
95 console.log(`Removed GHES ${release} markup from content and data files! Review and run tests.`)
96}

Callers 1

Calls 3

frontmatterFunction · 0.85
removeLiquidStatementsFunction · 0.85

Tested by

no test coverage detected