forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghes-release-notes.js
55 lines (45 loc) · 2.58 KB
/
ghes-release-notes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { merge } from 'lodash-es'
import { formatReleases, renderPatchNotes } from '../../lib/release-notes-utils.js'
import { all } from '../../lib/enterprise-server-releases.js'
import { getDeepDataByLanguage } from '../../lib/get-data.js'
export default async function ghesReleaseNotesContext(req, res, next) {
if (!(req.pagePath.endsWith('/release-notes') || req.pagePath.endsWith('/admin'))) return next()
const [requestedPlan, requestedRelease] = req.context.currentVersion.split('@')
if (requestedPlan !== 'enterprise-server') return next()
const ghesReleaseNotesEnglish = getDeepDataByLanguage('release-notes.enterprise-server', 'en')
const ghesReleaseNotesTranslated = getDeepDataByLanguage(
'release-notes.enterprise-server',
req.language
)
const ghesReleaseNotes = {}
merge(ghesReleaseNotes, ghesReleaseNotesEnglish)
merge(ghesReleaseNotes, ghesReleaseNotesTranslated)
// If the requested GHES release isn't found in data/release-notes/enterprise-server/*,
// and it IS a valid GHES release, try being helpful and redirecting to the old location.
// Otherwise, 404.
if (!Object.keys(ghesReleaseNotes).includes(requestedRelease.replace(/\./, '-'))) {
return all.includes(requestedRelease)
? res.redirect(`https://enterprise.github.com/releases/${requestedRelease}.0/notes`)
: next()
}
// Returns [{version, patches: [{version, patchVersion, intro, date, sections: { features: [], bugs: []...}} ]}]
req.context.ghesReleases = formatReleases(ghesReleaseNotes)
// Find the notes for the current release only
const currentReleaseNotes = req.context.ghesReleases.find(
(r) => r.version === requestedRelease
).patches
// Run the current release notes through the markdown rendering pipeline.
// Returns the current release's patches array: [{version, patchVersion, intro, date, sections}]
req.context.ghesReleaseNotes = await renderPatchNotes(currentReleaseNotes, req.context)
// GHES release notes on docs started with 2.20 but older release notes exist on enterprise.github.com.
// So we want to use _all_ GHES versions when calculating next and previous releases.
req.context.latestPatch = req.context.ghesReleaseNotes[0].version
req.context.latestRelease = all[0]
// Add convenience props for "Supported releases" section on GHES Admin landing page (NOT release notes).
req.context.ghesReleases.forEach((release) => {
release.firstPreviousRelease = all[all.findIndex((v) => v === release.version) + 1]
release.secondPreviousRelease =
all[all.findIndex((v) => v === release.firstPreviousRelease) + 1]
})
return next()
}