зеркало из https://github.com/github/docs.git
recover from Liquid rendering errors in release notes (#34484)
Co-authored-by: Rachael Sewell <rachmari@github.com>
This commit is contained in:
Родитель
19c8b713a2
Коммит
5004f4b67d
|
@ -60,7 +60,7 @@ export async function executeWithFallback(context, callable, fallback) {
|
||||||
try {
|
try {
|
||||||
return await callable(context)
|
return await callable(context)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isLiquidError(error)) {
|
if (isLiquidError(error) && context.currentLanguage !== 'en') {
|
||||||
const enContext = Object.assign({}, context, { currentLanguage: 'en' })
|
const enContext = Object.assign({}, context, { currentLanguage: 'en' })
|
||||||
return await fallback(enContext)
|
return await fallback(enContext)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { formatReleases, renderPatchNotes } from '../../lib/release-notes-utils.js'
|
import { formatReleases, renderPatchNotes } from '../../lib/release-notes-utils.js'
|
||||||
import { all } from '../../lib/enterprise-server-releases.js'
|
import { all } from '../../lib/enterprise-server-releases.js'
|
||||||
|
import { executeWithFallback } from '../../lib/render-with-fallback.js'
|
||||||
import { getReleaseNotes } from './get-release-notes.js'
|
import { getReleaseNotes } from './get-release-notes.js'
|
||||||
|
|
||||||
export default async function ghesReleaseNotesContext(req, res, next) {
|
export default async function ghesReleaseNotesContext(req, res, next) {
|
||||||
|
@ -28,7 +29,21 @@ export default async function ghesReleaseNotesContext(req, res, next) {
|
||||||
|
|
||||||
// Run the current release notes through the markdown rendering pipeline.
|
// Run the current release notes through the markdown rendering pipeline.
|
||||||
// Returns the current release's patches array: [{version, patchVersion, intro, date, sections}]
|
// Returns the current release's patches array: [{version, patchVersion, intro, date, sections}]
|
||||||
req.context.ghesReleaseNotes = await renderPatchNotes(currentReleaseNotes, req.context)
|
req.context.ghesReleaseNotes = await executeWithFallback(
|
||||||
|
req.context,
|
||||||
|
() => renderPatchNotes(currentReleaseNotes, req.context),
|
||||||
|
(enContext) => {
|
||||||
|
// Something in the release notes ultimately caused a Liquid
|
||||||
|
// rendering error. Let's start over and gather the English release
|
||||||
|
// notes instead.
|
||||||
|
const ghesReleaseNotes = getReleaseNotes('enterprise-server', 'en')
|
||||||
|
enContext.ghesReleases = formatReleases(ghesReleaseNotes)
|
||||||
|
const currentReleaseNotes = enContext.ghesReleases.find(
|
||||||
|
(r) => r.version === requestedRelease
|
||||||
|
).patches
|
||||||
|
return renderPatchNotes(currentReleaseNotes, enContext)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// GHES release notes on docs started with 2.20 but older release notes exist on enterprise.github.com.
|
// 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.
|
// So we want to use _all_ GHES versions when calculating next and previous releases.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче