1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/lib/get-map-topic-content.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
690 B
JavaScript

const findPage = require('./find-page')
// get the page.childArticles set on english map topics in lib/site-tree.js
module.exports = function getMapTopicContent (page, pageMap, redirects) {
const englishPage = page.languageCode !== 'en'
? findPage(`/${page.relativePath.replace(/.md$/, '')}`, pageMap, redirects, 'en')
: page
if (!englishPage) {
console.error(`cannot find english page: ${page.fullPath}`)
return
}
if (!englishPage.childArticles) {
console.error(`error getting child articles on map topic: ${page.fullPath}`)
return
}
return englishPage.childArticles
.map(article => `{% link_with_intro /${article.href} %}`)
.join('\n\n')
}