зеркало из https://github.com/github/docs.git
add remove-fpt helper function
This commit is contained in:
Родитель
927ead1d5f
Коммит
b511758057
|
@ -7,6 +7,7 @@ const yaml = require('js-yaml')
|
|||
const contentDir = path.join(process.cwd(), 'content')
|
||||
const frontmatter = require('@github-docs/frontmatter')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||
|
||||
// the product order is determined by data/products.yml
|
||||
const productsFile = path.join(process.cwd(), 'data/products.yml')
|
||||
|
@ -46,7 +47,7 @@ sortedProductIds.forEach(productId => {
|
|||
const toc = slash(path.join(dir, 'index.md'))
|
||||
const { data } = frontmatter(fs.readFileSync(toc, 'utf8'))
|
||||
const applicableVersions = getApplicableVersions(data.versions, toc)
|
||||
const href = `/${applicableVersions[0]}/${productId}`
|
||||
const href = removeFPTFromPath(`/${applicableVersions[0]}/${productId}`)
|
||||
|
||||
internalProducts[productId] = {
|
||||
id: productId,
|
||||
|
|
|
@ -10,7 +10,7 @@ const plans = [
|
|||
{ // free-pro-team is **not** a user-facing version and is stripped from URLs.
|
||||
// See lib/remove-fpt-from-path.js for details.
|
||||
plan: 'free-pro-team',
|
||||
planTitle: process.env.FEATURE_REMOVE_FPT ? 'GitHub.com' : 'Free, Pro, and Team',
|
||||
planTitle: 'GitHub.com',
|
||||
releases: [latestNonNumberedRelease],
|
||||
latestRelease: latestNonNumberedRelease,
|
||||
nonEnterpriseDefault: true, // permanent way to refer to this plan if the name changes
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const path = require('path')
|
||||
const findPage = require('./find-page')
|
||||
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||
|
||||
// rawLinks is an array of paths: [ '/foo' ]
|
||||
// we need to convert it to an array of localized objects: [ { href: '/en/foo', title: 'Foo', intro: 'Description here' } ]
|
||||
|
@ -12,7 +13,7 @@ module.exports = async (rawLinks, context, additionalProperties = []) => {
|
|||
for (const link of rawLinks) {
|
||||
const linkPath = link.href || link
|
||||
const version = context.currentVersion === 'homepage' ? nonEnterpriseDefaultVersion : context.currentVersion
|
||||
const href = path.join('/', context.currentLanguage, version, linkPath)
|
||||
const href = removeFPTFromPath(path.join('/', context.currentLanguage, version, linkPath))
|
||||
|
||||
const linkedPage = findPage(href, context.pages, context.redirects)
|
||||
if (!linkedPage) continue
|
||||
|
|
|
@ -3,6 +3,7 @@ const path = require('path')
|
|||
const patterns = require('./patterns')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const allVersions = require('./all-versions')
|
||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||
|
||||
class Permalink {
|
||||
constructor (languageCode, pageVersion, relativePath, title) {
|
||||
|
@ -13,7 +14,7 @@ class Permalink {
|
|||
|
||||
const permalinkSuffix = this.constructor.relativePathToSuffix(relativePath)
|
||||
|
||||
this.href = path.join('/', languageCode, pageVersion, permalinkSuffix)
|
||||
this.href = removeFPTFromPath(path.join('/', languageCode, pageVersion, permalinkSuffix))
|
||||
.replace(patterns.trailingSlash, '$1')
|
||||
|
||||
this.pageVersionTitle = allVersions[pageVersion].versionTitle
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const { latest, lastReleaseWithLegacyFormat } = require('../enterprise-server-releases')
|
||||
const { getPathWithoutLanguage, getPathWithLanguage } = require('../path-utils')
|
||||
const { getPathWithoutLanguage, getPathWithLanguage, getVersionStringFromPath } = require('../path-utils')
|
||||
const patterns = require('../patterns')
|
||||
const versionSatisfiesRange = require('../version-satisfies-range')
|
||||
const currentlySupportedVersions = Object.keys(require('../all-versions'))
|
||||
|
@ -11,6 +11,13 @@ const nonEnterpriseDefaultVersion = require('../non-enterprise-default-version')
|
|||
module.exports = function getOldPathsFromPath (currentPath, languageCode, currentVersion) {
|
||||
const oldPaths = new Set()
|
||||
|
||||
// This only applies to Dotcom paths, so no need to determine whether the version is deprecated
|
||||
// create old path /free-pro-team@latest/github from new path /github
|
||||
if (getVersionStringFromPath(currentPath) === nonEnterpriseDefaultVersion && !currentPath.includes(nonEnterpriseDefaultVersion)) {
|
||||
oldPaths.add(currentPath
|
||||
.replace(`/${languageCode}/`, `/${languageCode}/${nonEnterpriseDefaultVersion}/`))
|
||||
}
|
||||
|
||||
// ------ BEGIN LEGACY VERSION FORMAT REPLACEMENTS ------//
|
||||
// These remain relevant to handle legacy-formatted frontmatter redirects
|
||||
// and archived versions paths.
|
||||
|
@ -57,23 +64,6 @@ module.exports = function getOldPathsFromPath (currentPath, languageCode, curren
|
|||
// ------ BEGIN MODERN VERSION FORMAT REPLACEMENTS ------//
|
||||
if (currentlySupportedVersions.includes(currentVersion) || versionSatisfiesRange(currentVersion, `>${lastReleaseWithLegacyFormat}`)) {
|
||||
(new Set(oldPaths)).forEach(oldPath => {
|
||||
if (!process.env.FEATURE_REMOVE_FPT) {
|
||||
// create old path /github from new path /free-pro-team@latest/github
|
||||
oldPaths.add(oldPath
|
||||
.replace(`/${nonEnterpriseDefaultVersion}`, ''))
|
||||
|
||||
// create old path /free-pro-team/github from new path /free-pro-team@latest/github
|
||||
oldPaths.add(oldPath
|
||||
.replace('@latest', ''))
|
||||
}
|
||||
|
||||
// TODO THIS ONE IS TRICKY BECAUSE OF VERSIONS TO ENABLE
|
||||
// if (process.env.FEATURE_REMOVE_FPT) {
|
||||
// // create old path /free-pro-team@latest/github from new path /github
|
||||
// oldPaths.add(oldPath
|
||||
// .replace(`/${nonEnterpriseDefaultVersion}`, ''))
|
||||
// }
|
||||
|
||||
// create old path /enterprise/<version> from new path /enterprise-server@<version>
|
||||
oldPaths.add(oldPath
|
||||
.replace(/\/enterprise-server@(\d)/, '/enterprise/$1'))
|
||||
|
|
|
@ -4,6 +4,7 @@ const supportedVersions = new Set(Object.keys(require('../all-versions')))
|
|||
const getOldPathsFromPermalink = require('./get-old-paths-from-permalink')
|
||||
const { getVersionStringFromPath } = require('../path-utils')
|
||||
const { getNewVersionedPath } = require('../old-versions-utils')
|
||||
const removeFPTFromPath = require('../remove-fpt-from-path')
|
||||
|
||||
module.exports = function generateRedirectsForPermalinks (permalinks, redirectFrontmatter) {
|
||||
// account for Array or String frontmatter entries
|
||||
|
@ -18,6 +19,10 @@ module.exports = function generateRedirectsForPermalinks (permalinks, redirectFr
|
|||
// get an array of possible old paths, e.g., /desktop/guides/ from current permalink /desktop/
|
||||
const possibleOldPaths = getOldPathsFromPermalink(permalink.href, permalink.languageCode, permalink.pageVersion)
|
||||
|
||||
if (permalink.href === '/en/rest/reference/users') {
|
||||
console.log(possibleOldPaths)
|
||||
}
|
||||
|
||||
// for each old path, add a redirect to the current permalink
|
||||
possibleOldPaths.forEach(oldPath => {
|
||||
redirects[oldPath] = permalink.href
|
||||
|
@ -37,7 +42,7 @@ module.exports = function generateRedirectsForPermalinks (permalinks, redirectFr
|
|||
// get the old path for the current permalink version
|
||||
let versionedFrontmatterOldPath = path.join('/', permalink.languageCode, getNewVersionedPath(frontmatterOldPath))
|
||||
const versionFromPath = getVersionStringFromPath(versionedFrontmatterOldPath)
|
||||
versionedFrontmatterOldPath = versionedFrontmatterOldPath.replace(versionFromPath, permalink.pageVersion)
|
||||
versionedFrontmatterOldPath = removeFPTFromPath(versionedFrontmatterOldPath.replace(versionFromPath, permalink.pageVersion))
|
||||
|
||||
// add it to the redirects object
|
||||
redirects[versionedFrontmatterOldPath] = permalink.href
|
||||
|
|
|
@ -58,5 +58,7 @@ module.exports = function precompileRedirects (pageList, pageMap) {
|
|||
}
|
||||
})
|
||||
|
||||
require('fs').writeFileSync('.redirect-cache', JSON.stringify(allRedirects, null, 2))
|
||||
|
||||
return allRedirects
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
const slash = require('slash')
|
||||
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
||||
|
||||
// This is a convenience function to remove free-pro-team@latest from all
|
||||
// **user-facing** aspects of the site (particularly URLs) while continuing to support
|
||||
// free-pro-team@latest as a version both in the codebase and in content/data files.
|
||||
module.exports = function removeFPTFromPath (path) {
|
||||
return slash(path.replace(`/${nonEnterpriseDefaultVersion}`, ''))
|
||||
}
|
|
@ -9,6 +9,7 @@ const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
|||
const allVersions = require('./all-versions')
|
||||
const supportedVersions = Object.keys(allVersions)
|
||||
const supportedPlans = Object.values(allVersions).map(v => v.plan)
|
||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||
|
||||
// Content authors write links like `/some/article/path`, but they need to be
|
||||
// rewritten on the fly to match the current language and page version
|
||||
|
@ -79,7 +80,7 @@ function getNewHref (link, languageCode, version) {
|
|||
// ------ END ONE-OFF OVERRIDES ------//
|
||||
|
||||
// update the version in the link
|
||||
newHref = newHref.replace(versionFromHref, version)
|
||||
newHref = removeFPTFromPath(newHref.replace(versionFromHref, version))
|
||||
}
|
||||
|
||||
newHref = newHref.replace(patterns.trailingSlash, '$1')
|
||||
|
|
|
@ -6,6 +6,7 @@ const allVersions = Object.keys(require('./all-versions'))
|
|||
const { getVersionStringFromPath } = require('./path-utils')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const findPage = require('./find-page')
|
||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||
|
||||
// This module builds a localized tree of every page on the site
|
||||
// It includes single-source pages that have different variants
|
||||
|
@ -47,7 +48,7 @@ module.exports = async function buildSiteTree (pageMap, site, redirects) {
|
|||
|
||||
// item.hrefs have a default version via lib/all-products, so update to the current version
|
||||
const versionFromPath = getVersionStringFromPath(item.href)
|
||||
const versionedProductHref = path.join('/', languageCode, item.href.replace(versionFromPath, version))
|
||||
const versionedProductHref = removeFPTFromPath(path.join('/', languageCode, item.href.replace(versionFromPath, version)))
|
||||
|
||||
product.categories = buildCategoriesTree(page.tocItems, versionedProductHref, pageMap, redirects, version)
|
||||
|
||||
|
|
|
@ -29,19 +29,12 @@ module.exports = async (req, res, next) => {
|
|||
title: product.title
|
||||
}
|
||||
|
||||
// drop the version segment so pathParts now starts with /product
|
||||
if (!process.env.FEATURE_REMOVE_FPT) {
|
||||
// if this is not FPT, drop the version segment so pathParts now starts with /product
|
||||
// if this is FPT, there is no version segment so pathParts already starts with /product
|
||||
if (req.context.currentVersion !== nonEnterpriseDefaultVersion) {
|
||||
pathParts.shift()
|
||||
}
|
||||
|
||||
if (process.env.FEATURE_REMOVE_FPT) {
|
||||
// if this is not FPT, drop the version segment so pathParts now starts with /product
|
||||
// if this is FPT, there is no version segment so pathParts already starts with /product
|
||||
if (req.context.currentVersion !== nonEnterpriseDefaultVersion) {
|
||||
pathParts.shift()
|
||||
}
|
||||
}
|
||||
|
||||
if (!pathParts[1]) return next()
|
||||
|
||||
// get category path
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
const path = require('path')
|
||||
const rest = require('../../lib/rest')
|
||||
const removeFPTFromPath = require('../../lib/remove-fpt-from-path')
|
||||
|
||||
module.exports = async function (req, res, next) {
|
||||
req.context.rest = rest
|
||||
|
||||
// link to include in `Works with GitHub Apps` notes
|
||||
// e.g. /ja/rest/reference/apps or /en/enterprise/2.20/user/rest/reference/apps
|
||||
req.context.restGitHubAppsLink = path.join(
|
||||
req.context.restGitHubAppsLink = removeFPTFromPath(path.join(
|
||||
'/',
|
||||
req.context.currentLanguage,
|
||||
req.context.currentVersion,
|
||||
'/developers/apps'
|
||||
)
|
||||
))
|
||||
|
||||
// ignore requests to non-REST reference paths
|
||||
if (!req.path.includes('rest/reference')) return next()
|
||||
|
|
Загрузка…
Ссылка в новой задаче