1
0
mirror of synced 2025-12-22 11:26:57 -05:00
Files
docs/lib/get-map-topic-content.js
2020-12-15 11:52:53 -05:00

32 lines
1.4 KiB
JavaScript

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 (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 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']
}