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

site-tree-titles.js 2.3 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  1. const flat = require('flat')
  2. const renderContent = require('./render-content')
  3. const delimiter = '#'
  4. // render localized and product-version-aware page title or shortTitle
  5. module.exports = async function siteTreeTitles (siteTree, siteData) {
  6. // use a non-period delimiter because versions contain periods (like 2.19)
  7. const flatTree = flat(siteTree, { delimiter: delimiter })
  8. const titlesWithLiquid = Object.entries(flatTree)
  9. .filter(([path, shortOrLongTitle]) => path.endsWith('itle') && shortOrLongTitle && shortOrLongTitle.includes('{'))
  10. await Promise.all(titlesWithLiquid.map(async ([path, shortOrLongTitle]) => {
  11. const isShortTitle = /shortTitle$/.test(path)
  12. path = path.replace(`${delimiter}(shortT|t)itle`, '') // ignore the `title` path part for now
  13. // derive values from path parts
  14. const [
  15. languageCode,
  16. version,
  17. products,
  18. product,
  19. categories,
  20. category,
  21. maptopics,
  22. maptopic,
  23. articles,
  24. article
  25. ] = path.split(delimiter)
  26. // create context object for rendering of dynamic liquid data in page titles
  27. const ctx = {
  28. currentVersion: version,
  29. site: siteData[languageCode].site
  30. }
  31. const renderedShortOrLongTitle = await renderContent(shortOrLongTitle, ctx, { textOnly: true })
  32. // no product titles have liquid because we get them from lib/all-products.js
  33. // so we can assume all titles processed here will be either a category, maptopic, or article
  34. // we can also assume a category value will exist for any of these
  35. const currentCategory = siteTree[languageCode][version][products][product][categories][category]
  36. if (!maptopic) {
  37. isShortTitle
  38. ? currentCategory.shortTitle = renderedShortOrLongTitle
  39. : currentCategory.title = renderedShortOrLongTitle
  40. }
  41. let currentMaptopic
  42. if (maptopic) {
  43. currentMaptopic = currentCategory[maptopics][maptopic]
  44. if (!article) {
  45. isShortTitle
  46. ? currentMaptopic.shortTitle = renderedShortOrLongTitle
  47. : currentMaptopic.title = renderedShortOrLongTitle
  48. }
  49. }
  50. let currentArticle
  51. if (article) {
  52. currentArticle = currentMaptopic[articles][article]
  53. isShortTitle
  54. ? currentArticle.shortTitle = renderedShortOrLongTitle
  55. : currentArticle.title = renderedShortOrLongTitle
  56. }
  57. }))
  58. }
Tip!

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

Comments

Loading...