1
0
mirror of synced 2025-12-21 19:06:49 -05:00
Files
docs/lib/get-link-data.js
Vanessa Yuen b46da8dfc7 Sublanding page all guides section (#16869)
* get link liquid tag to accept variables as param

* new liquid tag `link_as_article_card`

* refactor link liquid tag slightly so we can control what props get rendered

* generalize filterCodeExample to use in all guides section

* pass in `js-filter-card-max` instead of hardcode max

* tweaks and add `data` to CSP for images

* add liquid tag tests

* add some browser tests for card filters

* we still need to rely on `getPathWithLanguage` for hrefs that already have the language code embedded


Co-authored-by: Emily Gould <4822039+emilyistoofunky@users.noreply.github.com>
2021-01-18 12:23:23 +00:00

33 lines
1.1 KiB
JavaScript

const path = require('path')
const findPage = require('./find-page')
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
const removeFPTFromPath = require('./remove-fpt-from-path')
// 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' } ]
module.exports = async (rawLinks, context) => {
if (!rawLinks) return
const links = []
for (const link of rawLinks) {
const linkPath = link.href || link
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) continue
const opts = { textOnly: true, encodeEntities: true }
links.push({
href,
title: await linkedPage.renderTitle(context, opts),
intro: await linkedPage.renderProp('intro', context, opts),
page: linkedPage
})
}
return links
}