Skip to content

Commit d752732

Browse files
committed
update refs to reinstated findPage()
1 parent f0244fa commit d752732

9 files changed

Lines changed: 22 additions & 9 deletions

File tree

lib/liquid-tags/link.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const assert = require('assert')
33
const Liquid = require('liquid')
44
const liquid = new Liquid.Engine()
55
const LiquidTag = require('./liquid-tag')
6+
const findPage = require('../find-page')
67
const getApplicableVersions = require('../get-applicable-versions')
78

89
// This class supports a set of link tags. Each tag expects one parameter, a language-agnostic href:
@@ -54,7 +55,7 @@ module.exports = class Link extends LiquidTag {
5455
fullPath = path.join('/', ctx.currentLanguage, fullPath)
5556

5657
// find the page based on the full path
57-
const page = ctx.pages[fullPath] || ctx.pages[ctx.redirects[fullPath]]
58+
const page = findPage(fullPath, ctx.pages, ctx.redirects)
5859

5960
// return an empty string if it's a hidden link on a non-hidden page (hidden links on hidden pages are OK)
6061
if (!page || (page.hidden && !ctx.page.hidden)) {

lib/patterns.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
oldEnterprisePath: /\/([a-z]{2}\/)?(enterprise\/)?(\S+?@(\S+?\/))?(\d.\d+\/)?(user[/$])?/,
4040
// new versioning format patterns
4141
adminProduct: /\/admin(\/|$|\?|#)/,
42+
insightsProduct: /\/insights(\/|$|\?|#)/,
4243
enterpriseServer: /\/enterprise-server@/,
4344
getEnterpriseServerNumber: /enterprise-server@(\d+\.\d+)/
4445
}

lib/redirects/get-docs-path-from-developer-path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const patterns = require('../patterns')
22
const { latest } = require('../enterprise-server-releases')
3-
const { getPathWithoutLanguage } = require('../path-utils')
3+
const { getPathWithoutLanguage, getPathWithoutVersion } = require('../path-utils')
44

55
// This function takes a known pre-migration path from developer.github.com and
66
// infers and returns a current, correct docs.github.com path.
@@ -73,7 +73,7 @@ module.exports = function getDocsPathFromDeveloperPath (oldDeveloperPath, allRed
7373

7474
// old developer routes that include 'enterprise-admin' should always redirect to enterprise server
7575
if (fragment && newPath.includes('/rest/reference/enterprise-admin') && !patterns.enterpriseServer.test(newPath)) {
76-
newPath = `/en/enterprise-server@${latest}${getPathWithoutLanguage(newPath)}`
76+
newPath = `/en/enterprise-server@${latest}${getPathWithoutLanguage(getPathWithoutVersion(newPath))}`
7777
}
7878

7979
// show an error if the page to be redirected to doesn't exist

lib/redirects/precompile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ module.exports = function precompileRedirects (pageList, pageMap) {
5858
}
5959
})
6060

61+
require('fs').writeFileSync('.redirect-cache', JSON.stringify(allRedirects, null, 2))
62+
6163
return allRedirects
6264
}

lib/rewrite-local-links.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ function getNewHref (link, languageCode, version) {
7272
if (patterns.adminProduct.test(hrefWithoutLang) && version === nonEnterpriseDefaultVersion) {
7373
version = `enterprise-server@${latest}`
7474
}
75+
76+
// insights links on dotcom always point to Enterprise
77+
if (patterns.insightsProduct.test(hrefWithoutLang) && version === nonEnterpriseDefaultVersion) {
78+
version = `enterprise-server@${latest}`
79+
}
7580
// ------ END ONE-OFF OVERRIDES ------//
7681

7782
// update the version in the link

lib/site-tree.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const allVersions = Object.keys(require('./all-versions'))
66
const { getVersionStringFromPath } = require('./path-utils')
77
const getApplicableVersions = require('./get-applicable-versions')
88
const removeFPTFromPath = require('./remove-fpt-from-path')
9+
const findPage = require('./find-page')
910

1011
// This module builds a localized tree of every page on the site
1112
// It includes single-source pages that have different variants
@@ -39,7 +40,7 @@ module.exports = async function buildSiteTree (pageMap, site, redirects) {
3940
product.href = path.join('/', languageCode, item.href)
4041

4142
// find the product TOC page so we have access to the TOC items
42-
const page = pageMap[item.href] || pageMap[redirects[item.href]]
43+
const page = findPage(item.href, pageMap, redirects)
4344

4445
// skip if page can't be found in this version
4546
if (!page) return
@@ -74,7 +75,7 @@ function buildCategoriesTree (tocItems, versionedProductHref, pageMap, redirects
7475
category.href = path.join(versionedProductHref, item.href)
7576

7677
// find the category TOC page and get its TOC items
77-
const page = pageMap[category.href] || pageMap[redirects[category.href]]
78+
const page = findPage(category.href, pageMap, redirects)
7879

7980
// skip if page can't be found in this version
8081
if (!page) return
@@ -118,7 +119,7 @@ function buildMaptopicsTree (tocItems, versionedCategoryHref, pageMap, redirects
118119
maptopic.href = path.join(versionedCategoryHref, item.href)
119120

120121
// find the category TOC page and get its TOC items
121-
const page = pageMap[maptopic.href] || pageMap[redirects[maptopic.href]]
122+
const page = findPage(maptopic.href, pageMap, redirects)
122123

123124
// skip if page can't be found in this version
124125
if (!page) return
@@ -153,7 +154,7 @@ function buildArticlesTree (tocItems, versionedCategoryHref, pageMap, redirects,
153154
article.href = path.join(versionedCategoryHref, item.href)
154155

155156
// find the category TOC page and get its TOC items
156-
const page = pageMap[article.href] || pageMap[redirects[article.href]]
157+
const page = findPage(article.href, pageMap, redirects)
157158

158159
// skip if page can't be found in this version
159160
if (!page) return

middleware/archived-enterprise-versions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { latest, firstVersionDeprecatedOnNewSite, lastVersionWithoutStubbedRedire
44
const patterns = require('../lib/patterns')
55
const versionSatisfiesRange = require('../lib/version-satisfies-range')
66
const isArchivedVersion = require('../lib/is-archived-version')
7+
const findPage = require('../lib/find-page')
78
const got = require('got')
89

910
// This module handles requests for deprecated GitHub Enterprise versions
@@ -76,7 +77,7 @@ function getFallbackRedirects (req, requestedVersion) {
7677
const pathWithNewVersion = req.path.replace(requestedVersion, latest)
7778

7879
// look for a page with the same path on a currently supported version
79-
const currentlySupportedPage = req.context.pages[pathWithNewVersion] || req.context.pages[req.context.redirects[pathWithNewVersion]]
80+
const currentlySupportedPage = findPage(pathWithNewVersion, req.context.pages, req.context.redirects)
8081
if (!currentlySupportedPage) return
8182

8283
// get an array of viable old paths

middleware/contextualizers/graphql.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const explorerUrl = process.env.NODE_ENV === 'production'
1111
module.exports = async (req, res, next) => {
1212
// ignore requests to non-GraphQL reference paths
1313
if (!req.path.includes('/graphql/')) return next()
14+
if (!allVersions[req.context.currentVersion]) return next()
1415

1516
// Get the relevant name of the GraphQL schema files for the current version
1617
// For example, free-pro-team@latest corresponds to dotcom,

middleware/featured-links.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path')
22
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
33
const removeFPTFromPath = require('../lib/remove-fpt-from-path')
4+
const findPage = require('../lib/find-page')
45

56
// this middleware adds properties to the context object
67
module.exports = async (req, res, next) => {
@@ -30,7 +31,7 @@ async function getLinkData (rawLinks, context) {
3031
const version = context.currentVersion === 'homepage' ? nonEnterpriseDefaultVersion : context.currentVersion
3132
const href = removeFPTFromPath(path.join('/', context.currentLanguage, version, linkPath))
3233

33-
const linkedPage = context.pages[href] || context.pages[context.redirects[href]]
34+
const linkedPage = findPage(href, context.pages, context.redirects)
3435
if (!linkedPage) continue
3536

3637
const opts = { textOnly: true, encodeEntities: true }

0 commit comments

Comments
 (0)