Skip to content

Commit 752edcf

Browse files
committed
use new static redirects file instead of precompiling on every server restart
1 parent a92789a commit 752edcf

2 files changed

Lines changed: 3 additions & 24 deletions

File tree

lib/redirects/precompile.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
const patterns = require('../patterns')
21
const { latest } = require('../enterprise-server-releases')
3-
const getOldPathsFromPermalink = require('../redirects/get-old-paths-from-permalink')
42
const getDocsPathFromDevPath = require('../redirects/get-docs-path-from-developer-path')
53
const DEVELOPER_ROUTES = require('../redirects/static/developer-docs-routes-for-supported-versions')
6-
const ARCHIVED_ROUTES = require('../redirects/static/archived-routes-from-213-to-217')
74

85
// This function runs at server warmup and precompiles possible redirect routes.
96
// It outputs them in key-value pairs within a neat Javascript object: { oldPath: newPath }
@@ -14,26 +11,7 @@ module.exports = function precompileRedirects (pageList, pageMap) {
1411
// create backwards-compatible old paths for page permalinks and frontmatter redirects
1512
pageList.forEach(page => Object.assign(allRedirects, page.buildRedirects()))
1613

17-
// 2. REDIRECTS FOR ARCHIVED ROUTES FROM 2.13 TO 2.17
18-
// Starting with 2.18, we updated the archival script to create stubbed HTML redirect files,
19-
// so those files do the heavy lifting. The handling here is only for blanket redirects
20-
// (like /articles -> /github) between 2.13 and 2.17. This works by creating possible
21-
// old/incoming paths from the archived routes JSON. Frontmatter redirects were lost
22-
// for 2.13-2.17, but the archived middleware tries to find fallbacks.
23-
ARCHIVED_ROUTES.forEach(archivedRoute => {
24-
const languageFromPath = archivedRoute.match(patterns.getLanguageCode)[1]
25-
const versionFromPath = archivedRoute.match(patterns.getEnterpriseVersionNumber)[1]
26-
27-
// get an array of possible old paths, e.g., /desktop/guides/ from /desktop/
28-
const possibleOldPaths = getOldPathsFromPermalink(archivedRoute, languageFromPath, versionFromPath)
29-
30-
// for each old path, add a redirect to the current route
31-
possibleOldPaths.forEach(oldPath => {
32-
allRedirects[oldPath] = archivedRoute
33-
})
34-
})
35-
36-
// 3. DEVELOPER ROUTES FOR CURRENTLY SUPPORTED VERSIONS
14+
// 2. DEVELOPER ROUTES FOR CURRENTLY SUPPORTED VERSIONS
3715
// From the list of developer docs routes, create new docs.github.com-style paths.
3816
// Note that the list only includes supported enterprise paths up to 2.21, which is
3917
// the last version that was available on developer.github.com before the migration.

middleware/archived-enterprise-versions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const versionSatisfiesRange = require('../lib/version-satisfies-range')
66
const isArchivedVersion = require('../lib/is-archived-version')
77
const findPage = require('../lib/find-page')
88
const got = require('got')
9+
const archvivedRedirects = require('../lib/redirects/static/archived-redirects-from-213-to-217')
910

1011
// This module handles requests for deprecated GitHub Enterprise versions
1112
// by routing them to static content in help-docs-archived-enterprise-versions
@@ -27,7 +28,7 @@ module.exports = async (req, res, next) => {
2728
// starting with 2.18, we updated the archival script to create stubbed HTML redirect files
2829
if (versionSatisfiesRange(requestedVersion, `>=${firstVersionDeprecatedOnNewSite}`) &&
2930
versionSatisfiesRange(requestedVersion, `<=${lastVersionWithoutStubbedRedirectFiles}`)) {
30-
const redirect = req.context.redirects[req.path]
31+
const redirect = archvivedRedirects[req.path]
3132
if (redirect && redirect !== req.path) {
3233
return res.redirect(301, redirect)
3334
}

0 commit comments

Comments
 (0)