|
1 | | -const { latest } = require('../enterprise-server-releases') |
2 | | -const getDocsPathFromDevPath = require('../redirects/get-docs-path-from-developer-path') |
3 | | -const DEVELOPER_ROUTES = require('../redirects/static/developer-docs-routes-for-supported-versions') |
| 1 | +const developerRedirects = require('../redirects/static/developer') |
4 | 2 |
|
5 | 3 | // This function runs at server warmup and precompiles possible redirect routes. |
6 | 4 | // It outputs them in key-value pairs within a neat Javascript object: { oldPath: newPath } |
7 | | -module.exports = function precompileRedirects (pageList, pageMap) { |
8 | | - const allRedirects = {} |
| 5 | +module.exports = function precompileRedirects (pageList) { |
| 6 | + const allRedirects = Object.assign({}, developerRedirects) |
9 | 7 |
|
10 | | - // 1. CURRENT PAGES PERMALINKS AND FRONTMATTER |
| 8 | + // CURRENT PAGES PERMALINKS AND FRONTMATTER |
11 | 9 | // create backwards-compatible old paths for page permalinks and frontmatter redirects |
12 | 10 | pageList.forEach(page => Object.assign(allRedirects, page.buildRedirects())) |
13 | 11 |
|
14 | | - // 2. DEVELOPER ROUTES FOR CURRENTLY SUPPORTED VERSIONS |
15 | | - // From the list of developer docs routes, create new docs.github.com-style paths. |
16 | | - // Note that the list only includes supported enterprise paths up to 2.21, which is |
17 | | - // the last version that was available on developer.github.com before the migration. |
18 | | - DEVELOPER_ROUTES.forEach(developerRoute => { |
19 | | - const newPath = getDocsPathFromDevPath(developerRoute, allRedirects, pageMap) |
20 | | - |
21 | | - // add the redirect to the object |
22 | | - allRedirects[developerRoute] = newPath |
23 | | - |
24 | | - // also add a variation with language code |
25 | | - const developerRouteWithLanguage = `/en${developerRoute}` |
26 | | - allRedirects[developerRouteWithLanguage] = newPath |
27 | | - |
28 | | - // although we only support developer Enterprise paths up to 2.21, we make |
29 | | - // an exception to always redirect versionless paths to the latest version |
30 | | - if (developerRoute.includes('/2.21/')) { |
31 | | - const newPathOnLatestVersion = newPath.replace('@2.21/', `@${latest}/`) |
32 | | - const developerRouteWithoutVersion = developerRoute.replace('/2.21/', '/') |
33 | | - const developerRouteWithLanguageWithoutVersion = `/en${developerRouteWithoutVersion}` |
34 | | - allRedirects[developerRouteWithoutVersion] = newPathOnLatestVersion |
35 | | - allRedirects[developerRouteWithLanguageWithoutVersion] = newPathOnLatestVersion |
36 | | - } |
37 | | - }) |
38 | | - |
39 | 12 | return allRedirects |
40 | 13 | } |
0 commit comments