* Create basic layout * Create stubbed out release note YAML * Get a real implementation going * Simplify using site-data * Add a real page to send from render-page.js * Use array of patches * Render patches * Add sidebar and breadcrumbs * Reverse order * Add date * Tweak labels * Redirect to entweb for missing versions * Render patch.intro * Move to separate files for patches * Show support for RC versions * Improve some comments * Sticky headers! * Remove a console log * Improve example formatting * Add a link on /admin * Add a schema and test * Move to /index.md, add version_num filter * Improve layout * Use <details> * Placeholder more realistic notes * Don't require links in index pages * Remove admin/index link for now * Remove unused frontmatter field * Add a test for middleware * Fix remaining YAML file to test CI * Update 2-rc.yml * Don't call it RC * Just push * Make a main a div * Fix a borked class * Lint YAML files * Improve Download link Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com> * Improve check order * Move to contextualizers * Use alternative version thing Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com> * Move back to `release-notes.md` * Use version for anchor IDs * Undo category-pages test change * Fix borked details layout in Chrome * Improve mobile setup * Render markdown in note tags * Use allVersions[currentVersion] again Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com> * Undo change to extended-markdown * Add whitespace so it renders markdown bits * Remove 2-22 files * Add check for any release notes * Fix the failing tests Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com>
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
const renderContent = require('../../lib/render-content')
|
|
const patterns = require('../../lib/patterns')
|
|
|
|
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 keys = Object.keys(releaseNotes)
|
|
// Turn { [key]: { notes, intro, date } }
|
|
// into [{ version, notes, intro, date }]
|
|
const patches = keys
|
|
.sort((a, b) => {
|
|
if (a > b) return -1
|
|
if (a < b) return 1
|
|
return 0
|
|
})
|
|
.map(key => ({ version: `${requestedVersion}.${key}`, ...releaseNotes[key] }))
|
|
|
|
const renderedPatches = await Promise.all(patches.map(async patch => {
|
|
// Render the intro block, it might contain markdown formatting
|
|
patch.intro = await renderContent(patch.intro, req.context)
|
|
|
|
// Run the notes through the markdown rendering pipeline
|
|
patch.notes = await Promise.all(patch.notes.map(async note => {
|
|
if (note.note) note.note = await renderContent(note.note, req.context)
|
|
return note
|
|
}))
|
|
|
|
// Sort the notes into sections
|
|
// Takes an array of notes: Array<{ note, type }>
|
|
// Turns it into { [type]: [{ note }] }
|
|
patch.sortedNotes = patch.notes.reduce((prev, curr) => {
|
|
const existingObj = prev.find(o => o.title === curr.type)
|
|
if (!existingObj) {
|
|
prev.push({ title: curr.type, notes: [curr] })
|
|
} else {
|
|
existingObj.notes.push(curr)
|
|
}
|
|
return prev
|
|
}, [])
|
|
|
|
return patch
|
|
}))
|
|
|
|
req.context.releaseNotes = renderedPatches
|
|
|
|
return next()
|
|
}
|