1
0
mirror of synced 2025-12-23 21:07:12 -05:00

use new module

This commit is contained in:
Sarah Schneider
2020-11-12 13:28:38 -05:00
parent 5822fa4747
commit 9bfaee1dc1
5 changed files with 64 additions and 77 deletions

View File

@@ -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