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

Function makeLiquidReplacements

script/content-migrations/use-short-versions.js:121–136  ·  view source on GitHub ↗
(replacementsObj, text)

Source from the content-addressed store, hash-verified

119}
120
121function makeLiquidReplacements(replacementsObj, text) {
122 let newText = text
123 Object.entries(replacementsObj).forEach(([oldCond, newCond]) => {
124 const oldCondRegex = new RegExp(`({%-?)\\s*?${escapeRegExp(oldCond)}\\s*?(-?%})`, 'g')
125 newText = newText
126 .replace(oldCondRegex, `$1 ${newCond} $2`)
127 // Content files use an old-school hack to ensure our old regex deprecation script DTRT, for example:
128 // `if enterpriseServerVersions contains currentVersion and currentVersion ver_gt "enterprise-server@2.21"`
129 // This script will change the above to `if ghes and ghes > 2.21`.
130 // But we don't need the hack for the new deprecation script, because it will change `if ghes > 2.21` to `if ghes`.
131 // So we can update this to the simpler `{% if ghes > 2.21 %}`.
132 .replace(/ghes and ghes/g, 'ghes')
133 })
134
135 return newText
136}
137
138// Versions map:
139// if currentVersion == "myVersion@myRelease" -> ifversion myVersionShort OR ifversion myVersionShort = @myRelease

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected