1
0
mirror of synced 2025-12-23 21:07:12 -05:00
Files
docs/lib/process-learning-tracks.js
Kevin Heis 42e785b0a8 Migrate CommonJS to ESM (#20301)
* First run of script

* Get the app running --- ish

* Get NextJS working

* Remove `node:`

* Get more tests passing in unit directory

* Update FailBot test to use nock

* Update test.yml

* Update Dockerfile

* tests/content fixes

* Update page.js

* Update build-changelog.js

* updating tests/routing

* Update orphan-tests.js

* updating tests/rendering

* Update .eslintrc.js

* Update .eslintrc.js

* Install jest/globals

* "linting" tests

* staging update to server.mjs

* Change '.github/allowed-actions.js' to a ESM export

* Lint

* Fixes for the main package.json

* Move Jest to be last in the npm test command so we can pass args

* Just use 'npm run lint' in the npm test command

* update algolia label script

* update openapi script

* update require on openapi

* Update enterprise-algolia-label.js

* forgot JSON.parse

* Update lunr-search-index.js

* Always explicitly include process.cwd() for JSON file reads pathed from project root

* update graphql/update-files.js script

* Update other npm scripts using jest to pass ESM NODE_OPTIONS

* Update check-for-enterprise-issues-by-label.js for ESM

* Update create-enterprise-issue.js for ESM

* Import jest global for browser tests

* Convert 'script/deploy' to ESM

Co-authored-by: Grace Park <gracepark@github.com>
Co-authored-by: James M. Greene <jamesmgreene@github.com>
2021-07-14 13:49:18 -07:00

63 lines
2.6 KiB
JavaScript

import renderContent from './render-content/index.js'
import getLinkData from './get-link-data.js'
import getApplicableVersions from './get-applicable-versions.js'
const renderOpts = { textOnly: true, encodeEntities: true }
// This module returns an object that contains a single featured learning track
// and an array of all the other learning tracks for the current version.
export default async function processLearningTracks (rawLearningTracks, context) {
const learningTracks = []
let featuredTrack
for await (const rawTrackName of rawLearningTracks) {
let isFeaturedTrack = false
// Track names in frontmatter may include Liquid conditionals.
const renderedTrackName = await renderContent(rawTrackName, context, renderOpts)
if (!renderedTrackName) continue
// Find the data for the current product and track name.
const track = context.site.data['learning-tracks'][context.currentProduct][renderedTrackName]
if (!track) continue
// If there is no `versions` prop in the learning track frontmatter, assume the track should display in all versions.
if (track.versions) {
const trackVersions = getApplicableVersions(track.versions)
// If the current version is not included, do not display the track.
if (!trackVersions.includes(context.currentVersion)) {
continue
}
}
const learningTrack = {
trackName: renderedTrackName,
title: await renderContent(track.title, context, renderOpts),
description: await renderContent(track.description, context, renderOpts),
// getLinkData respects versioning and only returns guides available in the current version;
// if no guides are available, the learningTrack.guides property will be an empty array.
guides: await getLinkData(track.guides, context)
}
// Determine if this is the featured track.
if (track.featured_track) {
// Featured track properties may be booleans or string that include Liquid conditionals with versioning.
// We need to parse any strings to determine if the featured track is relevant for this version.
isFeaturedTrack = track.featured_track === true || (await renderContent(track.featured_track, context, renderOpts) === 'true')
if (isFeaturedTrack) {
featuredTrack = learningTrack
}
}
// Only add the track to the array of tracks if there are guides in this version and it's not the featured track.
if (learningTrack.guides.length && !isFeaturedTrack) {
learningTracks.push(learningTrack)
}
}
return { featuredTrack, learningTracks }
}