diff --git a/lib/get-map-topic-content.js b/lib/get-map-topic-content.js index bb18544a2a..93b77aee9d 100644 --- a/lib/get-map-topic-content.js +++ b/lib/get-map-topic-content.js @@ -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') } diff --git a/lib/page.js b/lib/page.js index b2850f8772..f9adabbe5c 100644 --- a/lib/page.js +++ b/lib/page.js @@ -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! diff --git a/lib/site-tree.js b/lib/site-tree.js index eb605188ac..894085627e 100644 --- a/lib/site-tree.js +++ b/lib/site-tree.js @@ -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 })