Skip to content

Commit 754d59a

Browse files
committed
parse featured links to support Liquid conditionals
1 parent 76227bd commit 754d59a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/get-link-data.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require('path')
22
const findPage = require('./find-page')
33
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
44
const removeFPTFromPath = require('./remove-fpt-from-path')
5+
const renderContent = require('./render-content')
56

67
// rawLinks is an array of paths: [ '/foo' ]
78
// we need to convert it to an array of localized objects: [ { href: '/en/foo', title: 'Foo', intro: 'Description here' } ]
@@ -27,15 +28,17 @@ module.exports = async (rawLinks, context, option = { title: true, intro: true }
2728
}
2829

2930
const processLink = async (link, context, option) => {
30-
const linkPath = link.href || link
31+
const opts = { textOnly: true, encodeEntities: true }
32+
// Parse the link in case it includes Liquid conditionals
33+
const linkPath = await renderContent((link.href || link), context, opts)
34+
if (!linkPath) return null
35+
3136
const version = context.currentVersion === 'homepage' ? nonEnterpriseDefaultVersion : context.currentVersion
3237
const href = removeFPTFromPath(path.join('/', context.currentLanguage, version, linkPath))
3338

3439
const linkedPage = findPage(href, context.pages, context.redirects)
3540
if (!linkedPage) return null
3641

37-
const opts = { textOnly: true, encodeEntities: true }
38-
3942
const result = { href, page: linkedPage }
4043

4144
if (option.title) {

0 commit comments

Comments
 (0)