Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

get-map-topic-content.js 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  1. const { get, last } = require('lodash')
  2. const { getLanguageCode } = require('../lib/patterns')
  3. // get the childArticles set on map topics in lib/site-tree.js
  4. module.exports = function getMapTopicContent (productId, siteTree, currentLanguage, currentVersion, currentPath) {
  5. const maptopicPath = currentPath
  6. const categoryPath = currentPath.replace(new RegExp(`/${last(currentPath.split('/'))}$`), '')
  7. const siteTreePath = getSiteTreePath(currentVersion, productId, categoryPath, maptopicPath)
  8. let childArticles = get(siteTree[currentLanguage], siteTreePath)
  9. // try falling back to English if needed
  10. if (!childArticles && currentLanguage !== 'en') {
  11. const englishCategoryPath = categoryPath.replace(getLanguageCode, '/en')
  12. const englishMaptopicPath = maptopicPath.replace(getLanguageCode, '/en')
  13. const englishSiteTreePath = getSiteTreePath(currentVersion, productId, englishCategoryPath, englishMaptopicPath)
  14. childArticles = get(siteTree.en, englishSiteTreePath)
  15. }
  16. if (!childArticles) {
  17. console.error(`can't find child articles for map topic ${currentPath}`)
  18. return ''
  19. }
  20. return childArticles
  21. .map(article => `{% link_with_intro /${article.href} %}`)
  22. .join('\n\n')
  23. }
  24. function getSiteTreePath (version, productId, categoryPath, maptopicPath) {
  25. return [version, 'products', productId, 'categories', categoryPath, 'maptopics', maptopicPath, 'childArticles']
  26. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...