Skip to content

Commit

Permalink
parse featured links to support Liquid conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahs committed Mar 26, 2021
1 parent 76227bd commit 754d59a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/get-link-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const findPage = require('./find-page')
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
const removeFPTFromPath = require('./remove-fpt-from-path')
const renderContent = require('./render-content')

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

const processLink = async (link, context, option) => {
const linkPath = link.href || link
const opts = { textOnly: true, encodeEntities: true }
// Parse the link in case it includes Liquid conditionals
const linkPath = await renderContent((link.href || link), context, opts)
if (!linkPath) return null

const version = context.currentVersion === 'homepage' ? nonEnterpriseDefaultVersion : context.currentVersion
const href = removeFPTFromPath(path.join('/', context.currentLanguage, version, linkPath))

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

const opts = { textOnly: true, encodeEntities: true }

const result = { href, page: linkedPage }

if (option.title) {
Expand Down

0 comments on commit 754d59a

Please sign in to comment.