1
0
mirror of synced 2025-12-22 19:34:15 -05:00
Files
docs/lib/find-page-in-version.js
James M. Greene fb30a0766f Unravel pages (the array + map object) (#16708)
* Revise the 'pages' module to export two methods: 'loadPages' and 'loadPageMap'

Update all existing references to use 'loadPages' for now

* Remove explicit Promise resolutions on loadPage* methods

* Condense reduction method into its now-singular usage spot

* Opt for for-of instead of forEach

* Make require of pages in warm-server more explicit

* Be more explicit about find-page using a pageMap

* Be more explicit about find-page-in-version using a pageMap

* Be more explicit about site-tree using a pageMap

* Extract the map creation from loadPageMap

* Be more explicit about using a pageMap

* Update redirects precompile to take two arguments: pageList, pageMap

* Rename internal loadPages method to loadPageList

* Clarify pageMap is what is stored in context.pages

* Use loadPageMap in tests and stuff
2020-12-03 22:31:10 +00:00

23 lines
926 B
JavaScript

const findPage = require('./find-page')
const getApplicableVersions = require('./get-applicable-versions')
module.exports = function findPageInVersion (href, pageMap, redirects, languageCode, version, isDotcomOnly = false) {
// findPage() will throw an error if an English page can't be found
const page = findPage(href, pageMap, redirects, languageCode)
if (!page) return null
// if the link is on the homepage, return the page as soon as it's found
if (version === 'homepage') return page
// if the link is dotcom-only, return the page as soon as it's found
if (isDotcomOnly) return page
// otherwise, get the versions that the found page is available in
const applicableVersions = getApplicableVersions(page.versions, page.fullPath)
// return null if the found page's available versions do not include the specified version
if (!applicableVersions.includes(version)) return null
return page
}