1
0
mirror of synced 2026-01-06 06:02:35 -05:00
Files
docs/middleware/contextualizers/ghes-release-notes.js
2022-11-17 15:32:25 +00:00

50 lines
2.5 KiB
JavaScript

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()
let ghesReleaseNotes = getDeepDataByLanguage('release-notes.enterprise-server', req.language)
if ((!ghesReleaseNotes || Object.keys(ghesReleaseNotes).length === 0) && req.language !== 'en') {
ghesReleaseNotes = getDeepDataByLanguage('release-notes.enterprise-server', 'en')
}
// 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()
}