1
0
mirror of synced 2025-12-25 02:17:36 -05:00

update the middleware

This commit is contained in:
Sarah Schneider
2021-05-07 17:34:43 -04:00
parent f11632f1c5
commit b1e1a3835f

View File

@@ -1,7 +1,7 @@
const enterpriseReleases = require('../../lib/enterprise-server-releases').supported
const { supported, latest } = require('../../lib/enterprise-server-releases')
const { sortReleasesByDate, sortPatchKeys, renderPatchNotes, getAllReleases } = require('../../lib/release-notes-utils')
module.exports = async (req, res, next) => {
module.exports = async function releaseNotesContext (req, res, next) {
// The `/release-notes` sub-path
if (!req.path.endsWith('/release-notes')) return next()
@@ -27,11 +27,14 @@ module.exports = async (req, res, next) => {
const patches = sortPatchKeys(currentReleaseNotes, requestedRelease, { semverSort: hasNumberedReleases })
req.context.releaseNotes = await Promise.all(patches.map(async patch => renderPatchNotes(patch, req.context)))
req.context.releases = getAllReleases(enterpriseReleases, releaseNotesPerPlan, hasNumberedReleases)
req.context.releases = getAllReleases(supported, releaseNotesPerPlan, hasNumberedReleases)
const releaseIndex = enterpriseReleases.findIndex(release => release === requestedRelease)
req.context.nextRelease = enterpriseReleases[releaseIndex - 1]
req.context.prevRelease = enterpriseReleases[releaseIndex + 1]
const releaseIndex = supported.findIndex(release => release === requestedRelease)
req.context.nextRelease = supported[releaseIndex - 1]
req.context.prevRelease = supported[releaseIndex + 1]
req.context.latestPatch = patches[0].version
req.context.latestRelease = latest
}
// GHAE gets handled here...
@@ -41,6 +44,15 @@ module.exports = async (req, res, next) => {
req.context.releaseNotes = await Promise.all(sortedNotes.map(async patch => renderPatchNotes(patch, req.context)))
req.context.releases = getAllReleases(sortedReleases, releaseNotesPerPlan, hasNumberedReleases)
// do some date format massaging, since we want the friendly date to render as the "version"
.map(r => {
const d = r.patches[0].friendlyDate.split(' ')
d.splice(1, 1)
r.version = d.join(' ')
return r
})
req.context.latestPatch = sortedNotes[0].date
}
return next()