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

Function removeDeprecatedFrontmatter

script/helpers/remove-deprecated-frontmatter.js:1–47  ·  view source on GitHub ↗
(
  file,
  frontmatterVersions,
  releaseToDeprecate,
  nextOldestRelease
)

Source from the content-addressed store, hash-verified

1export default function removeDeprecatedFrontmatter(
2 file,
3 frontmatterVersions,
4 releaseToDeprecate,
5 nextOldestRelease
6) {
7 // skip files with no Enterprise Server versions frontmatter
8 if (!frontmatterVersions) return
9 if (!frontmatterVersions.ghes) return
10
11 const ghesRange = frontmatterVersions.ghes
12
13 // skip files with versions frontmatter that already applies to all enterprise-server releases
14 if (ghesRange === '*') return
15
16 // if the release to deprecate is 2.13, and the FM is either '>=2.13', '>2.13', or '>=2.14',
17 // we can safely change the FM to ghes: '*'
18 const appliesToAllSupportedGhesReleases =
19 ghesRange === `>=${releaseToDeprecate}` ||
20 ghesRange === `>${releaseToDeprecate}` ||
21 ghesRange === `>=${nextOldestRelease}`
22
23 if (appliesToAllSupportedGhesReleases) {
24 frontmatterVersions.ghes = '*'
25 return
26 }
27
28 // if the release to deprecate is 2.13, and the FM is either '=2.13', '<2.13', '<=2.13', or '<2.14',
29 // delete (aka deprecate) the ghes frontmatter property.
30 const appliesToNoSupportedGhesReleases =
31 ghesRange === `=${releaseToDeprecate}` ||
32 ghesRange === `<${releaseToDeprecate}` ||
33 ghesRange === `<=${releaseToDeprecate}` ||
34 ghesRange === `<${nextOldestRelease}`
35
36 if (appliesToNoSupportedGhesReleases) {
37 // Throw a warning if there are no other frontmatter versions specified.
38 if (Object.keys(frontmatterVersions).length === 1) {
39 console.log(
40 `Warning! ${file} has frontmatter versioning that will make it never appear when ${releaseToDeprecate} is deprecated. The article should probably be removed.`
41 )
42 return
43 }
44
45 delete frontmatterVersions.ghes
46 }
47}

Callers 2

mainFunction · 0.85
processFrontmatterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected