1
0
mirror of synced 2025-12-31 06:02:42 -05:00
Files
docs/middleware/featured-links.js
Jason Etcovitch dd91c5a707 "Guides" section of the Actions landing page (#16216)
* Add custom hover shadows

* Support avatars

* Add guide-card include

* Use it in product-landing

* Add gradient styles

* Add guides frontmatter

* Use guideArticles instead of full objects

* Add support for authors

* Add support for category header

* Just pass the whole page

* Use it

* guide.url => guide.href

* Use `*.githubusercontent.com`

* Fix mobile card width

* Remove showDescription check

* Use featureLinks.guideCards

* Forgot an if

* Remove support banner

* Just use login instead of name/avatarUrl

* Change card spacing

* Use circular avatars

* Add margin beneath "Guides"

* Use smaller font

* Even moar spacing

* Remove category

* Remove lead text, move button to bottom right

* update guide cards

* Change author of setting up ci to GitHub

* Attribute node js guide to GitHub

* Add author tag to powershell guide

* update top guides section with correct actions links

* Enforce size for single avatars

* Adjust spacing

Co-authored-by: Cynthia Rich <crichID@users.noreply.github.com>
2020-11-11 12:53:46 -05:00

53 lines
1.9 KiB
JavaScript

const findPage = require('../lib/find-page')
const getApplicableVersions = require('../lib/get-applicable-versions')
const { getVersionedPathWithLanguage } = require('../lib/path-utils')
// this middleware adds properties to the context object
module.exports = async (req, res, next) => {
if (!req.context.page) return next()
if (!(req.context.page.relativePath.endsWith('index.md') || req.context.page.layout === 'product-landing')) return next()
if (!req.context.page.featuredLinks) return next()
req.context.featuredLinks = {}
for (const key in req.context.page.featuredLinks) {
req.context.featuredLinks[key] = await getLinkData(req.context.page.featuredLinks[key], req.context)
}
return next()
}
// 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' } ]
async function getLinkData (rawLinks, context) {
if (!rawLinks) return
const links = []
for (const link of rawLinks) {
const href = link.href
? getVersionedPathWithLanguage(link.href, context.currentVersion, context.currentLanguage)
: getVersionedPathWithLanguage(link, context.currentVersion, context.currentLanguage)
const linkedPage = findPage(href, context.pages, context.redirects, context.currentLanguage)
if (!linkedPage) continue
const applicableVersions = getApplicableVersions(linkedPage.versions, linkedPage.fullPath)
// skip link if this is not the homepage and the link's versions do not include the current version
if (context.currentVersion !== 'homepage' && !applicableVersions.includes(context.currentVersion)) 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
}