@@ -2,18 +2,19 @@ const flat = require('flat')
22const renderContent = require ( './render-content' )
33const delimiter = '#'
44
5- // render localized and product-version-aware page title
6- // note this only supports titles with liquid, not short titles
5+ // render localized and product-version-aware page title or shortTitle
76
87module . exports = async function siteTreeTitles ( siteTree , siteData ) {
98 // use a non-period delimiter because versions contain periods (like 2.19)
109 const flatTree = flat ( siteTree , { delimiter : delimiter } )
1110
1211 const titlesWithLiquid = Object . entries ( flatTree )
13- . filter ( ( [ path , title ] ) => path . endsWith ( 'title ' ) && title . includes ( '{' ) )
12+ . filter ( ( [ path , shortOrLongTitle ] ) => path . endsWith ( 'itle ' ) && shortOrLongTitle && shortOrLongTitle . includes ( '{' ) )
1413
15- await Promise . all ( titlesWithLiquid . map ( async ( [ path , title ] ) => {
16- path = path . replace ( `${ delimiter } title` , '' ) // ignore the `title` path part for now
14+ await Promise . all ( titlesWithLiquid . map ( async ( [ path , shortOrLongTitle ] ) => {
15+ const isShortTitle = / s h o r t T i t l e $ / . test ( path )
16+
17+ path = path . replace ( `${ delimiter } (shortT|t)itle` , '' ) // ignore the `title` path part for now
1718
1819 // derive values from path parts
1920 const [
@@ -31,29 +32,39 @@ module.exports = async function siteTreeTitles (siteTree, siteData) {
3132
3233 // create context object for rendering of dynamic liquid data in page titles
3334 const ctx = {
34- page : { version } ,
35+ currentVersion : version ,
3536 site : siteData [ languageCode ] . site
3637 }
3738
38- const renderedTitle = await renderContent ( title , ctx , { textOnly : true } )
39+ const renderedShortOrLongTitle = await renderContent ( shortOrLongTitle , ctx , { textOnly : true } )
3940
4041 // no product titles have liquid because we get them from lib/all-products.js
4142 // so we can assume all titles processed here will be either a category, maptopic, or article
4243 // we can also assume a category value will exist for any of these
4344 const currentCategory = siteTree [ languageCode ] [ version ] [ products ] [ product ] [ categories ] [ category ]
4445
45- if ( ! maptopic ) currentCategory . title = renderedTitle
46+ if ( ! maptopic ) {
47+ isShortTitle
48+ ? currentCategory . shortTitle = renderedShortOrLongTitle
49+ : currentCategory . title = renderedShortOrLongTitle
50+ }
4651
4752 let currentMaptopic
4853 if ( maptopic ) {
4954 currentMaptopic = currentCategory [ maptopics ] [ maptopic ]
50- if ( ! article ) currentMaptopic . title = renderedTitle
55+ if ( ! article ) {
56+ isShortTitle
57+ ? currentMaptopic . shortTitle = renderedShortOrLongTitle
58+ : currentMaptopic . title = renderedShortOrLongTitle
59+ }
5160 }
5261
5362 let currentArticle
5463 if ( article ) {
5564 currentArticle = currentMaptopic [ articles ] [ article ]
56- currentArticle . title = renderedTitle
65+ isShortTitle
66+ ? currentArticle . shortTitle = renderedShortOrLongTitle
67+ : currentArticle . title = renderedShortOrLongTitle
5768 }
5869 } ) )
5970}
0 commit comments