Skip to content

Commit 5fa3dd8

Browse files
authored
Merge pull request #16949 from github/do-not-mutate-page-in-sitetree
Refactor how we get map topic content
2 parents c412bd9 + 53e1ffd commit 5fa3dd8

3 files changed

Lines changed: 10 additions & 22 deletions

File tree

lib/get-map-topic-content.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
const findPage = require('./find-page')
1+
// get the childArticles set on map topics in lib/site-tree.js
2+
module.exports = function getMapTopicContent (parentProductId, breadcrumbs, siteTree) {
3+
const childArticles = siteTree.products[parentProductId].categories[breadcrumbs.category.href].maptopics[breadcrumbs.maptopic.href].childArticles
24

3-
// get the page.childArticles set on english map topics in lib/site-tree.js
4-
module.exports = function getMapTopicContent (page, pageMap, redirects) {
5-
const englishPage = page.languageCode !== 'en'
6-
? findPage(`/${page.relativePath.replace(/.md$/, '')}`, pageMap, redirects, 'en')
7-
: page
8-
9-
if (!englishPage) {
10-
console.error(`cannot find english page: ${page.fullPath}`)
11-
return
12-
}
13-
14-
if (!englishPage.childArticles) {
15-
console.error(`error getting child articles on map topic: ${page.fullPath}`)
16-
return
5+
if (!childArticles) {
6+
console.error(`can't find child articles from siteTree for map topic '${breadcrumbs.maptopic.href}'`)
177
}
188

19-
return englishPage.childArticles
9+
return childArticles
2010
.map(article => `{% link_with_intro /${article.href} %}`)
2111
.join('\n\n')
2212
}

lib/page.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class Page {
148148
this.shortTitle = await renderContent(this.shortTitle, context, { textOnly: true, encodeEntities: true })
149149

150150
let markdown = this.mapTopic
151-
? getMapTopicContent(this, context.pages, context.redirects)
151+
// get the map topic child articles from the siteTree
152+
? getMapTopicContent(this.parentProduct.id, context.breadcrumbs, context.siteTree[context.currentLanguage][context.currentVersion])
152153
: this.markdown
153154

154155
// If the article is interactive parse the React!

lib/site-tree.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,13 @@ function buildMaptopicsTree (tocItems, versionedCategoryHref, pageMap, redirects
125125
// if this is not a maptopic, return early
126126
if (!page.mapTopic) return
127127

128-
const childArticles = getChildArticles(tocItems, item.href)
129-
130128
maptopic.title = page.title
131129
maptopic.shortTitle = page.shortTitle
132130
maptopic.hidden = page.hidden
133-
134131
// make the child articles accessible to the page object for maptopic rendering
135-
if (!page.childArticles) page.childArticles = childArticles
132+
maptopic.childArticles = getChildArticles(tocItems, item.href)
133+
maptopic.articles = buildArticlesTree(maptopic.childArticles, versionedCategoryHref, pageMap, redirects, version, languageCode)
136134

137-
maptopic.articles = buildArticlesTree(page.childArticles, versionedCategoryHref, pageMap, redirects, version, languageCode)
138135
maptopicTree[versionedMaptopicHref] = maptopic
139136
})
140137

0 commit comments

Comments
 (0)