зеркало из https://github.com/github/docs.git
update refs to reinstated findPage()
This commit is contained in:
Родитель
f0244fa645
Коммит
d752732b16
|
@ -3,6 +3,7 @@ const assert = require('assert')
|
|||
const Liquid = require('liquid')
|
||||
const liquid = new Liquid.Engine()
|
||||
const LiquidTag = require('./liquid-tag')
|
||||
const findPage = require('../find-page')
|
||||
const getApplicableVersions = require('../get-applicable-versions')
|
||||
|
||||
// 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 {
|
|||
fullPath = path.join('/', ctx.currentLanguage, fullPath)
|
||||
|
||||
// find the page based on the full path
|
||||
const page = ctx.pages[fullPath] || ctx.pages[ctx.redirects[fullPath]]
|
||||
const page = findPage(fullPath, ctx.pages, ctx.redirects)
|
||||
|
||||
// return an empty string if it's a hidden link on a non-hidden page (hidden links on hidden pages are OK)
|
||||
if (!page || (page.hidden && !ctx.page.hidden)) {
|
||||
|
|
|
@ -39,6 +39,7 @@ module.exports = {
|
|||
oldEnterprisePath: /\/([a-z]{2}\/)?(enterprise\/)?(\S+?@(\S+?\/))?(\d.\d+\/)?(user[/$])?/,
|
||||
// new versioning format patterns
|
||||
adminProduct: /\/admin(\/|$|\?|#)/,
|
||||
insightsProduct: /\/insights(\/|$|\?|#)/,
|
||||
enterpriseServer: /\/enterprise-server@/,
|
||||
getEnterpriseServerNumber: /enterprise-server@(\d+\.\d+)/
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const patterns = require('../patterns')
|
||||
const { latest } = require('../enterprise-server-releases')
|
||||
const { getPathWithoutLanguage } = require('../path-utils')
|
||||
const { getPathWithoutLanguage, getPathWithoutVersion } = require('../path-utils')
|
||||
|
||||
// This function takes a known pre-migration path from developer.github.com and
|
||||
// infers and returns a current, correct docs.github.com path.
|
||||
|
@ -73,7 +73,7 @@ module.exports = function getDocsPathFromDeveloperPath (oldDeveloperPath, allRed
|
|||
|
||||
// old developer routes that include 'enterprise-admin' should always redirect to enterprise server
|
||||
if (fragment && newPath.includes('/rest/reference/enterprise-admin') && !patterns.enterpriseServer.test(newPath)) {
|
||||
newPath = `/en/enterprise-server@${latest}${getPathWithoutLanguage(newPath)}`
|
||||
newPath = `/en/enterprise-server@${latest}${getPathWithoutLanguage(getPathWithoutVersion(newPath))}`
|
||||
}
|
||||
|
||||
// show an error if the page to be redirected to doesn't exist
|
||||
|
|
|
@ -58,5 +58,7 @@ module.exports = function precompileRedirects (pageList, pageMap) {
|
|||
}
|
||||
})
|
||||
|
||||
require('fs').writeFileSync('.redirect-cache', JSON.stringify(allRedirects, null, 2))
|
||||
|
||||
return allRedirects
|
||||
}
|
||||
|
|
|
@ -72,6 +72,11 @@ function getNewHref (link, languageCode, version) {
|
|||
if (patterns.adminProduct.test(hrefWithoutLang) && version === nonEnterpriseDefaultVersion) {
|
||||
version = `enterprise-server@${latest}`
|
||||
}
|
||||
|
||||
// insights links on dotcom always point to Enterprise
|
||||
if (patterns.insightsProduct.test(hrefWithoutLang) && version === nonEnterpriseDefaultVersion) {
|
||||
version = `enterprise-server@${latest}`
|
||||
}
|
||||
// ------ END ONE-OFF OVERRIDES ------//
|
||||
|
||||
// update the version in the link
|
||||
|
|
|
@ -6,6 +6,7 @@ const allVersions = Object.keys(require('./all-versions'))
|
|||
const { getVersionStringFromPath } = require('./path-utils')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||
const findPage = require('./find-page')
|
||||
|
||||
// This module builds a localized tree of every page on the site
|
||||
// It includes single-source pages that have different variants
|
||||
|
@ -39,7 +40,7 @@ module.exports = async function buildSiteTree (pageMap, site, redirects) {
|
|||
product.href = path.join('/', languageCode, item.href)
|
||||
|
||||
// find the product TOC page so we have access to the TOC items
|
||||
const page = pageMap[item.href] || pageMap[redirects[item.href]]
|
||||
const page = findPage(item.href, pageMap, redirects)
|
||||
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
@ -74,7 +75,7 @@ function buildCategoriesTree (tocItems, versionedProductHref, pageMap, redirects
|
|||
category.href = path.join(versionedProductHref, item.href)
|
||||
|
||||
// find the category TOC page and get its TOC items
|
||||
const page = pageMap[category.href] || pageMap[redirects[category.href]]
|
||||
const page = findPage(category.href, pageMap, redirects)
|
||||
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
@ -118,7 +119,7 @@ function buildMaptopicsTree (tocItems, versionedCategoryHref, pageMap, redirects
|
|||
maptopic.href = path.join(versionedCategoryHref, item.href)
|
||||
|
||||
// find the category TOC page and get its TOC items
|
||||
const page = pageMap[maptopic.href] || pageMap[redirects[maptopic.href]]
|
||||
const page = findPage(maptopic.href, pageMap, redirects)
|
||||
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
@ -153,7 +154,7 @@ function buildArticlesTree (tocItems, versionedCategoryHref, pageMap, redirects,
|
|||
article.href = path.join(versionedCategoryHref, item.href)
|
||||
|
||||
// find the category TOC page and get its TOC items
|
||||
const page = pageMap[article.href] || pageMap[redirects[article.href]]
|
||||
const page = findPage(article.href, pageMap, redirects)
|
||||
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
|
|
@ -4,6 +4,7 @@ const { latest, firstVersionDeprecatedOnNewSite, lastVersionWithoutStubbedRedire
|
|||
const patterns = require('../lib/patterns')
|
||||
const versionSatisfiesRange = require('../lib/version-satisfies-range')
|
||||
const isArchivedVersion = require('../lib/is-archived-version')
|
||||
const findPage = require('../lib/find-page')
|
||||
const got = require('got')
|
||||
|
||||
// This module handles requests for deprecated GitHub Enterprise versions
|
||||
|
@ -76,7 +77,7 @@ function getFallbackRedirects (req, requestedVersion) {
|
|||
const pathWithNewVersion = req.path.replace(requestedVersion, latest)
|
||||
|
||||
// look for a page with the same path on a currently supported version
|
||||
const currentlySupportedPage = req.context.pages[pathWithNewVersion] || req.context.pages[req.context.redirects[pathWithNewVersion]]
|
||||
const currentlySupportedPage = findPage(pathWithNewVersion, req.context.pages, req.context.redirects)
|
||||
if (!currentlySupportedPage) return
|
||||
|
||||
// get an array of viable old paths
|
||||
|
|
|
@ -11,6 +11,7 @@ const explorerUrl = process.env.NODE_ENV === 'production'
|
|||
module.exports = async (req, res, next) => {
|
||||
// ignore requests to non-GraphQL reference paths
|
||||
if (!req.path.includes('/graphql/')) return next()
|
||||
if (!allVersions[req.context.currentVersion]) return next()
|
||||
|
||||
// Get the relevant name of the GraphQL schema files for the current version
|
||||
// For example, free-pro-team@latest corresponds to dotcom,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const path = require('path')
|
||||
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
|
||||
const removeFPTFromPath = require('../lib/remove-fpt-from-path')
|
||||
const findPage = require('../lib/find-page')
|
||||
|
||||
// this middleware adds properties to the context object
|
||||
module.exports = async (req, res, next) => {
|
||||
|
@ -30,7 +31,7 @@ async function getLinkData (rawLinks, context) {
|
|||
const version = context.currentVersion === 'homepage' ? nonEnterpriseDefaultVersion : context.currentVersion
|
||||
const href = removeFPTFromPath(path.join('/', context.currentLanguage, version, linkPath))
|
||||
|
||||
const linkedPage = context.pages[href] || context.pages[context.redirects[href]]
|
||||
const linkedPage = findPage(href, context.pages, context.redirects)
|
||||
if (!linkedPage) continue
|
||||
|
||||
const opts = { textOnly: true, encodeEntities: true }
|
||||
|
|
Загрузка…
Ссылка в новой задаче