зеркало из https://github.com/github/docs.git
use new module
This commit is contained in:
Родитель
5822fa4747
Коммит
9bfaee1dc1
|
@ -1,11 +1,11 @@
|
|||
const cheerio = require('cheerio')
|
||||
const findPage = require('./find-page')
|
||||
const findPageInVersion = require('./find-page-in-version')
|
||||
const renderContent = require('./render-content')
|
||||
const rewriteLocalLinks = require('./rewrite-local-links')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
||||
const { getPathWithoutLanguage } = require('./path-utils')
|
||||
const { getEnterpriseVersionNumber } = require('./patterns')
|
||||
const { deprecated } = require('./enterprise-server-releases')
|
||||
const { getEnterpriseVersionNumber, adminProduct } = require('./patterns')
|
||||
const { deprecated, latest } = require('./enterprise-server-releases')
|
||||
|
||||
// internal links will have a language code by the time we're testing them
|
||||
// we also want to capture same-page anchors (#foo)
|
||||
|
@ -59,7 +59,15 @@ module.exports = async function checkLinks ($, page, context, version, checkedLi
|
|||
if (gheVersionInLink && deprecated.includes(gheVersionInLink[1])) continue
|
||||
|
||||
// look for linked page
|
||||
const linkedPage = findPage(link, context.pages, context.redirects, languageCode)
|
||||
const isDotcomOnly = $(internalLink).attr('class')
|
||||
|
||||
// special case for GHES Admin links on dotcom, which are not broken; they go to the latest GHES version
|
||||
let versionToCheck = version
|
||||
if (version === nonEnterpriseDefaultVersion && adminProduct.test(link)) {
|
||||
versionToCheck = `enterprise-server@${latest}`
|
||||
}
|
||||
|
||||
const linkedPage = findPageInVersion(link, context.pages, context.redirects, languageCode, versionToCheck, isDotcomOnly)
|
||||
|
||||
if (!linkedPage) {
|
||||
brokenLinks.links.push({ 'broken link': link, reason: 'linked page not found' })
|
||||
|
@ -79,16 +87,6 @@ module.exports = async function checkLinks ($, page, context, version, checkedLi
|
|||
.filter(operation => operation.operationId.startsWith(docsPath))
|
||||
}
|
||||
|
||||
// finding the linked page isn't enough if it's a github.com page; also need to check versions
|
||||
if (linkedPage.relativePath.startsWith('github')) {
|
||||
const linkedPageVersions = getApplicableVersions(linkedPage.versions, linkedPage.relativePath)
|
||||
|
||||
if (!linkedPageVersions.includes(version) && $(internalLink).attr('class') !== 'dotcom-only') {
|
||||
brokenLinks.links.push({ 'broken link': link, reason: `${version} not found in linked page versions`, 'linked page': linkedPage.fullPath })
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// collect elements of the page that may contain links
|
||||
const linkedPageContent = linkedPage.relativePath.includes('graphql/reference/objects')
|
||||
? linkedPage.markdown + context.graphql.prerenderedObjectsForCurrentVersion.html
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
const cheerio = require('cheerio')
|
||||
const findPage = require('./find-page')
|
||||
const findPageInVersion = require('./find-page-in-version')
|
||||
const renderContent = require('./render-content')
|
||||
const rewriteLocalLinks = require('./rewrite-local-links')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
||||
const { getPathWithoutLanguage } = require('./path-utils')
|
||||
const { getEnterpriseVersionNumber } = require('./patterns')
|
||||
const { deprecated } = require('./enterprise-server-releases')
|
||||
const { getEnterpriseVersionNumber, adminProduct } = require('./patterns')
|
||||
const { deprecated, latest } = require('./enterprise-server-releases')
|
||||
|
||||
// internal links will have a language code by the time we're testing them
|
||||
// we also want to capture same-page anchors (#foo)
|
||||
|
@ -59,23 +59,21 @@ module.exports = async function checkLinks ($, page, context, version, checkedLi
|
|||
if (gheVersionInLink && deprecated.includes(gheVersionInLink[1])) continue
|
||||
|
||||
// look for linked page
|
||||
const linkedPage = findPage(link, context.pages, context.redirects, languageCode)
|
||||
const isDotcomOnly = $(internalLink).attr('class')
|
||||
|
||||
// special case for GHES Admin links on dotcom, which are not broken; they go to the latest GHES version
|
||||
let versionToCheck = version
|
||||
if (version === nonEnterpriseDefaultVersion && adminProduct.test(link)) {
|
||||
versionToCheck = `enterprise-server@${latest}`
|
||||
}
|
||||
|
||||
const linkedPage = findPageInVersion(link, context.pages, context.redirects, languageCode, versionToCheck, isDotcomOnly)
|
||||
|
||||
if (!linkedPage) {
|
||||
brokenLinks.links.push({ 'broken link': link, reason: 'linked page not found' })
|
||||
continue
|
||||
}
|
||||
|
||||
// finding the linked page isn't enough if it's a github.com page; also need to check versions
|
||||
if (linkedPage.relativePath.startsWith('github')) {
|
||||
const linkedPageVersions = getApplicableVersions(linkedPage.versions, linkedPage.relativePath)
|
||||
|
||||
if (!linkedPageVersions.includes(version) && $(internalLink).attr('class') !== 'dotcom-only') {
|
||||
brokenLinks.links.push({ 'broken link': link, reason: `${version} not found in linked page versions`, 'linked page': linkedPage.fullPath })
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// don't check anchors on developers content
|
||||
if (linkedPage.relativePath.match(/^(rest|graphql|developers)/)) continue
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@ const Liquid = require('liquid')
|
|||
const liquid = new Liquid.Engine()
|
||||
const { getPathWithLanguage } = require('../path-utils')
|
||||
const LiquidTag = require('./liquid-tag')
|
||||
const findPage = require('../find-page')
|
||||
const getApplicableVersions = require('../get-applicable-versions')
|
||||
const findPageInVersion = require('../find-page-in-version')
|
||||
|
||||
// This class supports a set of link tags. Each tag expects one parameter, a language-agnostic href:
|
||||
//
|
||||
|
@ -56,20 +55,11 @@ module.exports = class Link extends LiquidTag {
|
|||
fullPath = getPathWithLanguage(fullPath, ctx.currentLanguage)
|
||||
|
||||
// find the page based on the full path
|
||||
const page = findPage(fullPath, ctx.pages, ctx.redirects, ctx.currentLanguage)
|
||||
|
||||
// workaround for localized links that can't be found because they are not in sync
|
||||
if (!page) return ''
|
||||
|
||||
// get versions of the found page
|
||||
const applicableVersions = getApplicableVersions(page.versions, fullPath)
|
||||
|
||||
// check whether the page versions include the current version
|
||||
const shouldLinkRenderInCurrentVersion = applicableVersions.includes(ctx.currentVersion)
|
||||
const page = findPageInVersion(fullPath, ctx.pages, ctx.redirects, ctx.currentLanguage, ctx.currentVersion)
|
||||
|
||||
// if found page should NOT render in current version, return early with an empty string
|
||||
// also return if it's a hidden link on a non-hidden page (hidden links on hidden pages are OK)
|
||||
if (!shouldLinkRenderInCurrentVersion || (page.hidden && !ctx.page.hidden)) {
|
||||
if (!page || (page.hidden && !ctx.page.hidden)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
|
|
|
@ -22,19 +22,30 @@ function getVersionedPathWithoutLanguage (href, version) {
|
|||
// example: enterprise-server@2.22 or free-pro-team@latest
|
||||
let versionFromPath = getVersionStringFromPath(href)
|
||||
|
||||
// if versionFromPath doesn't match any current versions, this may be an old
|
||||
// versioned path that should be converted to new versioned path. Examples:
|
||||
// OLD: /enterprise/2.22/admin/installation OR /enterprise/admin/installation
|
||||
// NEW: /enterprise-server@2.22/admin/installation
|
||||
// OLD: /desktop/installing-and-configuring-github-desktop
|
||||
// NEW: /free-pro-team@latest/desktop/installing-and-configuring-github-desktop
|
||||
// if the version found is not a currently supported version...
|
||||
let productObjectFromPath
|
||||
if (!Object.keys(allVersions).includes(versionFromPath)) {
|
||||
href = getNewVersionedPath(href)
|
||||
versionFromPath = getVersionStringFromPath(href)
|
||||
// first check if the first segment is instead a current product;
|
||||
// example: /admin/foo or /desktop/foo
|
||||
productObjectFromPath = allProducts[versionFromPath]
|
||||
|
||||
// if so, add the first supported version for that product to the href
|
||||
if (productObjectFromPath) {
|
||||
href = path.join('/', productObjectFromPath.versions[0], href)
|
||||
versionFromPath = productObjectFromPath.versions[0]
|
||||
} else {
|
||||
// otherwise, this may be an old path that should be converted to new path;
|
||||
// OLD: /enterprise/2.22/admin/installation OR /enterprise/admin/installation
|
||||
// NEW: /enterprise-server@2.22/admin/installation
|
||||
href = getNewVersionedPath(href)
|
||||
versionFromPath = getVersionStringFromPath(href)
|
||||
}
|
||||
}
|
||||
|
||||
// derive the product from the path (e.g., github or admin) and get corresponding object
|
||||
const productObjectFromPath = getProductObjectFromPath(href)
|
||||
// if not previously found, derive the product object from the path (e.g., github or admin)
|
||||
if (!productObjectFromPath) {
|
||||
productObjectFromPath = getProductObjectFromPath(href)
|
||||
}
|
||||
|
||||
// if the product's versions don't include the specified version, nothing to change!
|
||||
if (productObjectFromPath && !productObjectFromPath.versions.includes(version)) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
const path = require('path')
|
||||
const findPage = require('./find-page')
|
||||
const getApplicableVersions = require('./get-applicable-versions')
|
||||
const findPageInVersion = require('./find-page-in-version')
|
||||
const products = Object.values(require('../lib/all-products'))
|
||||
const { getVersionedPathWithoutLanguage } = require('./path-utils')
|
||||
const languageCodes = Object.keys(require('./languages'))
|
||||
|
@ -39,7 +38,10 @@ module.exports = async function buildSiteTree (pages, site, redirects) {
|
|||
product.href = item.href
|
||||
|
||||
// find the product TOC page and get TOC items
|
||||
const page = findPage(item.href, pages, redirects, languageCode)
|
||||
const page = findPageInVersion(item.href, pages, redirects, languageCode, version)
|
||||
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
||||
product.categories = buildCategoriesTree(page.tocItems, item.href, pages, redirects, version, languageCode)
|
||||
|
||||
|
@ -69,17 +71,13 @@ function buildCategoriesTree (tocItems, productHref, pages, redirects, version,
|
|||
category.href = versionedCategoryHref
|
||||
|
||||
// find the category TOC page and get its TOC items
|
||||
const page = findPage(categoryHref, pages, redirects, languageCode)
|
||||
const page = findPageInVersion(categoryHref, pages, redirects, languageCode, version)
|
||||
|
||||
// skip if translated page can't be found
|
||||
if (!page && languageCode !== 'en') return
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
||||
category.title = page.shortTitle || page.title
|
||||
|
||||
if (!getApplicableVersions(page.versions, page.fullPath).includes(version)) {
|
||||
return
|
||||
}
|
||||
|
||||
// support standalone pages at the category level, like actions/quickstart.md
|
||||
if (!page.tocItems) {
|
||||
category.standalone = true
|
||||
|
@ -120,18 +118,14 @@ function buildMaptopicsTree (tocItems, categoryHref, pages, redirects, version,
|
|||
|
||||
// we already have access to the child articles via the category TOC items
|
||||
// but we still need the page to get the available versions
|
||||
const page = findPage(maptopicHref, pages, redirects, languageCode)
|
||||
const page = findPageInVersion(maptopicHref, pages, redirects, languageCode, version)
|
||||
|
||||
// skip if translated page can't be found
|
||||
if (!page && languageCode !== 'en') return
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
||||
// if this is not a maptopic, return early
|
||||
if (!page.mapTopic) return
|
||||
|
||||
if (!getApplicableVersions(page.versions, page.fullPath).includes(version)) {
|
||||
return
|
||||
}
|
||||
|
||||
const childArticles = getChildArticles(tocItems, item.href)
|
||||
|
||||
maptopic.title = page.title
|
||||
|
@ -163,17 +157,13 @@ function buildArticlesTree (tocItems, categoryHref, pages, redirects, version, l
|
|||
const versionedArticleHref = getVersionedPathWithoutLanguage(articleHref, version)
|
||||
article.href = versionedArticleHref
|
||||
|
||||
const page = findPage(articleHref, pages, redirects, languageCode)
|
||||
const page = findPageInVersion(articleHref, pages, redirects, languageCode, version)
|
||||
|
||||
// skip if translated page can't be found
|
||||
if (!page && languageCode !== 'en') return
|
||||
// skip if page can't be found in this version
|
||||
if (!page) return
|
||||
|
||||
article.title = page.shortTitle || page.title
|
||||
|
||||
if (!getApplicableVersions(page.versions, page.fullPath).includes(version)) {
|
||||
return
|
||||
}
|
||||
|
||||
articleTree[versionedArticleHref] = article
|
||||
})
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче