refactor map topic module to not use breadcrumbs

This commit is contained in:
Sarah Schneider 2020-12-15 11:52:53 -05:00
Родитель dca55a0257
Коммит c859f853dc
2 изменённых файлов: 23 добавлений и 4 удалений

Просмотреть файл

@ -1,12 +1,31 @@
const { get, last } = require('lodash')
const { getLanguageCode } = require('../lib/patterns')
// 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
module.exports = function getMapTopicContent (productId, siteTree, currentLanguage, currentVersion, currentPath) {
const maptopicPath = currentPath
const categoryPath = currentPath.replace(`/${last(currentPath.split('/'))}`, '')
const siteTreePath = getSiteTreePath(currentVersion, productId, categoryPath, maptopicPath)
let childArticles = get(siteTree[currentLanguage], siteTreePath)
// try falling back to English if needed
if (!childArticles && currentLanguage !== 'en') {
const englishCategoryPath = categoryPath.replace(getLanguageCode, '/en')
const englishMaptopicPath = maptopicPath.replace(getLanguageCode, '/en')
const englishSiteTreePath = getSiteTreePath(currentVersion, productId, englishCategoryPath, englishMaptopicPath)
childArticles = get(siteTree.en, englishSiteTreePath)
}
if (!childArticles) {
console.error(`can't find child articles from siteTree for map topic '${breadcrumbs.maptopic.href}'`)
console.error('can\'t find child articles for map topic')
return ''
}
return childArticles
.map(article => `{% link_with_intro /${article.href} %}`)
.join('\n\n')
}
function getSiteTreePath (version, productId, categoryPath, maptopicPath) {
return [version, 'products', productId, 'categories', categoryPath, 'maptopics', maptopicPath, 'childArticles']
}

Просмотреть файл

@ -149,7 +149,7 @@ class Page {
let markdown = this.mapTopic
// get the map topic child articles from the siteTree
? getMapTopicContent(this.parentProduct.id, context.breadcrumbs, context.siteTree[context.currentLanguage][context.currentVersion])
? getMapTopicContent(this.parentProduct.id, context.siteTree, context.currentLanguage, context.currentVersion, context.currentPath)
: this.markdown
// If the article is interactive parse the React!