* Add 2.22.0 * Add 2.22.1 * Add 2.22.2 * Add 2.22.3 * Add 2.22.4 * Lint YAML files * intro shouldn't be required * Align all notes * Full height sidebar * Make the sidebar full height properly * Get the real layout going * Include full name * Move details > summary around * Fix sticky sidebar * Tweak bottom of page * Add more label colors * Change heading title * Don't be <details>, change sticky header * Include other releases' info * Show prev/next links * Change sidenav to show all releases * Fix ordering of chevron * Fix link underlines * Collapsing minor versions * Moar padding * Setup schema for sub-sections * Update a YAML file to match schema * Redo rendering/sorting logic * Update layout * Convert remaining notes * Improve schema * Use proper min properties * Custom bullet points * Show details control for version picker * Improve layout on small screens * One more tiny fix * Order by semver * Use proper version in details * Fix extra arrows showing up * Change label colors * Pass the reference check * Add gradients * Gradient all the things
83 lines
3.0 KiB
JavaScript
83 lines
3.0 KiB
JavaScript
const semver = require('semver')
|
|
const renderContent = require('../../lib/render-content')
|
|
const patterns = require('../../lib/patterns')
|
|
const enterpriseReleases = require('../../lib/enterprise-server-releases').supported
|
|
|
|
/**
|
|
* Turn { [key]: { notes, intro, date } }
|
|
* into [{ version, notes, intro, date }]
|
|
*/
|
|
function sortPatchKeys (release, version) {
|
|
const keys = Object.keys(release)
|
|
.map(key => ({ version: `${version}.${key}`, patchVersion: key, ...release[key] }))
|
|
return keys
|
|
.sort((a, b) => {
|
|
if (semver.gt(a.version, b.version)) return -1
|
|
if (semver.lt(a.version, b.version)) return 1
|
|
return 0
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Render each note in the given patch, by looping through the
|
|
* sections and rendering either `note` or `note.notes` in the
|
|
* case of a sub-section
|
|
*/
|
|
async function renderPatchNotes (patch, ctx) {
|
|
// Run the notes through the markdown rendering pipeline
|
|
for (const key in patch.sections) {
|
|
await Promise.all(patch.sections[key].map(async (noteOrHeading, index) => {
|
|
patch.sections[key][index] = typeof noteOrHeading === 'string'
|
|
? await renderContent(noteOrHeading, ctx)
|
|
: {
|
|
...noteOrHeading,
|
|
notes: await Promise.all(noteOrHeading.notes.map(note => renderContent(note, ctx)))
|
|
}
|
|
}))
|
|
}
|
|
|
|
return patch
|
|
}
|
|
|
|
module.exports = async (req, res, next) => {
|
|
// The `/release-notes` sub-path
|
|
if (!req.path.endsWith('/release-notes')) return next()
|
|
|
|
// ignore paths that don't have an enterprise version number
|
|
if (!patterns.getEnterpriseServerNumber.test(req.path)) return next()
|
|
|
|
// extract enterprise version from path, e.g. 2.16
|
|
const requestedVersion = req.path.match(patterns.getEnterpriseServerNumber)[1]
|
|
|
|
const versionString = `${requestedVersion.replace(/\./g, '-')}`
|
|
|
|
const allReleaseNotes = req.context.site.data['release-notes']
|
|
|
|
// This version doesn't have any release notes - let's be helpful and redirect
|
|
// to the notes on `enterprise.github.com`
|
|
if (!allReleaseNotes || !allReleaseNotes[versionString]) {
|
|
return res.redirect(`https://enterprise.github.com/releases/${requestedVersion}.0/notes`)
|
|
}
|
|
|
|
const releaseNotes = allReleaseNotes[versionString]
|
|
const patches = sortPatchKeys(releaseNotes, requestedVersion)
|
|
|
|
req.context.releaseNotes = await Promise.all(patches.map(async patch => renderPatchNotes(patch, req.context)))
|
|
|
|
// Put together information about other releases
|
|
req.context.releases = enterpriseReleases.map(version => {
|
|
const ret = { version }
|
|
if (!req.context.site.data['release-notes']) return ret
|
|
const release = req.context.site.data['release-notes'][version.replace(/\./g, '-')]
|
|
if (!release) return ret
|
|
const patches = sortPatchKeys(release, version)
|
|
return { ...ret, patches }
|
|
})
|
|
|
|
const releaseIndex = enterpriseReleases.findIndex(release => release === requestedVersion)
|
|
req.context.nextRelease = enterpriseReleases[releaseIndex - 1]
|
|
req.context.prevRelease = enterpriseReleases[releaseIndex + 1]
|
|
|
|
return next()
|
|
}
|