1
0
mirror of synced 2026-01-08 21:02:10 -05:00

Merge pull request #16949 from github/do-not-mutate-page-in-sitetree

Refactor how we get map topic content
This commit is contained in:
Sarah Schneider
2020-12-14 15:55:41 -05:00
committed by GitHub
3 changed files with 10 additions and 22 deletions

View File

@@ -1,22 +1,12 @@
const findPage = require('./find-page')
// get the childArticles set on map topics in lib/site-tree.js
module.exports = function getMapTopicContent (parentProductId, breadcrumbs, siteTree) {
const childArticles = siteTree.products[parentProductId].categories[breadcrumbs.category.href].maptopics[breadcrumbs.maptopic.href].childArticles
// 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 (!childArticles) {
console.error(`can't find child articles from siteTree for map topic '${breadcrumbs.maptopic.href}'`)
}
if (!englishPage.childArticles) {
console.error(`error getting child articles on map topic: ${page.fullPath}`)
return
}
return englishPage.childArticles
return childArticles
.map(article => `{% link_with_intro /${article.href} %}`)
.join('\n\n')
}

View File

@@ -148,7 +148,8 @@ class Page {
this.shortTitle = await renderContent(this.shortTitle, context, { textOnly: true, encodeEntities: true })
let markdown = this.mapTopic
? getMapTopicContent(this, context.pages, context.redirects)
// get the map topic child articles from the siteTree
? getMapTopicContent(this.parentProduct.id, context.breadcrumbs, context.siteTree[context.currentLanguage][context.currentVersion])
: this.markdown
// If the article is interactive parse the React!

View File

@@ -125,16 +125,13 @@ function buildMaptopicsTree (tocItems, versionedCategoryHref, pageMap, redirects
// if this is not a maptopic, return early
if (!page.mapTopic) return
const childArticles = getChildArticles(tocItems, item.href)
maptopic.title = page.title
maptopic.shortTitle = page.shortTitle
maptopic.hidden = page.hidden
// make the child articles accessible to the page object for maptopic rendering
if (!page.childArticles) page.childArticles = childArticles
maptopic.childArticles = getChildArticles(tocItems, item.href)
maptopic.articles = buildArticlesTree(maptopic.childArticles, versionedCategoryHref, pageMap, redirects, version, languageCode)
maptopic.articles = buildArticlesTree(page.childArticles, versionedCategoryHref, pageMap, redirects, version, languageCode)
maptopicTree[versionedMaptopicHref] = maptopic
})