MCPcopy Index your code
hub / github.com/github/docs / processLearningTracks

Function processLearningTracks

lib/process-learning-tracks.js:11–126  ·  view source on GitHub ↗
(rawLearningTracks, context)

Source from the content-addressed store, hash-verified

9// This module returns an object that contains a single featured learning track
10// and an array of all the other learning tracks for the current version.
11export default async function processLearningTracks(rawLearningTracks, context) {
12 const learningTracks = []
13
14 let featuredTrack
15
16 if (!context.currentProduct) {
17 throw new Error(`Missing context.currentProduct value.`)
18 }
19
20 for (const rawTrackName of rawLearningTracks) {
21 let isFeaturedTrack = false
22
23 // Track names in frontmatter may include Liquid conditionals.
24 const renderedTrackName = await renderContent(rawTrackName, context, renderOpts)
25 if (!renderedTrackName) continue
26
27 // Find the data for the current product and track name.
28
29 if (context.currentProduct.includes('.')) {
30 throw new Error(`currentProduct can not contain a . (${context.currentProduct})`)
31 }
32 if (renderedTrackName.includes('.')) {
33 throw new Error(`renderedTrackName can not contain a . (${renderedTrackName})`)
34 }
35
36 // Note: this will use the translated learning tracks and automatically
37 // fall back to English if they don't exist on disk in the translation.
38 const track = getDataByLanguage(
39 `learning-tracks.${context.currentProduct}.${renderedTrackName}`,
40 context.currentLanguage
41 )
42 if (!track) {
43 throw new Error(`No learning track called '${renderedTrackName}'.`)
44 }
45
46 // If the current language isn't 'en' we need to prepare and have the
47 // English quivalent ready.
48 // We do this for two reasons:
49 //
50 // 1. For each learning-track .yml file (in data) always want the
51 // English values for `guides`, `versions`, `featured_track`.
52 // Meaning, for the translated learning tracks we only keep the
53 // `title` and `description`.
54 //
55 // 2. When we attempt to render the translated learning tracks'
56 // `title` and `description`, if they are failing to render,
57 // we need to have the English `title` and `description` to
58 // fall back to.
59 //
60 let enTrack
61 if (context.currentLanguage !== 'en') {
62 enTrack = getDataByLanguage(
63 `learning-tracks.${context.currentProduct}.${renderedTrackName}`,
64 'en'
65 )
66 // Sometimes the translations have more than just translated the
67 // `title` and `description`, but also things that don't make sense
68 // to translate like `guides` and `versions`. Always draw that

Callers 1

_renderMethod · 0.85

Calls 3

executeWithFallbackFunction · 0.90
renderContentFunction · 0.85
getApplicableVersionsFunction · 0.85

Tested by

no test coverage detected