Skip to content

Commit 89da003

Browse files
committed
account for the fact that featured_track values may either be booleans or strings to be parsed
1 parent 1019de7 commit 89da003

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lib/process-learning-tracks.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const getLinkData = require('./get-link-data')
33

44
const renderOpts = { textOnly: true, encodeEntities: true }
55

6+
// This module returns an object that contains a single featured learning track
7+
// and an array of all the other learning tracks for the current version.
68
module.exports = async function processLearningTracks (rawLearningTracks, context) {
79
const learningTracks = []
810

@@ -30,17 +32,16 @@ module.exports = async function processLearningTracks (rawLearningTracks, contex
3032

3133
// Determine if this is the featured track.
3234
if (track.featured_track) {
33-
// Featured track properties may include Liquid conditionals with versioning, so we need to parse to
34-
// determine if the featured track is relevant for this version.
35-
const parsed = await renderContent(track.featured_track, context, renderOpts)
36-
if (parsed === 'true') {
35+
// Featured track properties may be booleans or string that include Liquid conditionals with versioning.
36+
// We need to parse any strings to determine if the featured track is relevant for this version.
37+
isFeaturedTrack = typeof track.featured_track === 'boolean' || (await renderContent(track.featured_track, context, renderOpts) === 'true')
38+
39+
if (isFeaturedTrack) {
3740
featuredTrack = learningTrack
38-
isFeaturedTrack = true
3941
}
4042
}
4143

42-
// Only add the track to the array of tracks if there are guides in this version
43-
// and it's not the featured track.
44+
// Only add the track to the array of tracks if there are guides in this version and it's not the featured track.
4445
if (learningTrack.guides.length && !isFeaturedTrack) {
4546
learningTracks.push(learningTrack)
4647
}

tests/content/lint-files.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,24 +725,25 @@ describe('lint learning tracks', () => {
725725
expect(errors.length, errorMessage).toBe(0)
726726
})
727727

728-
it.only('has one and only one featured track per version', async () => {
728+
it('has one and only one featured track per version', async () => {
729729
const featuredTracks = {}
730730
const context = { enterpriseServerVersions }
731731

732732
await Promise.all(allVersions.map(async (version) => {
733733
const featuredTracksPerVersion = (await Promise.all(Object.values(dictionary).map(async (entry) => {
734734
if (!entry.featured_track) return
735735
context.currentVersion = version
736-
return renderContent(entry.featured_track, context, { textOnly: true, encodeEntities: true })
736+
const isFeaturedLink = typeof entry.featured_track === 'boolean' || (await renderContent(entry.featured_track, context, { textOnly: true, encodeEntities: true }) === 'true')
737+
return isFeaturedLink
737738
})))
738-
.filter(val => val === 'true')
739+
.filter(Boolean)
739740

740-
featuredTracks[version] = featuredTracksPerVersion
741+
featuredTracks[version] = featuredTracksPerVersion.length
741742
}))
742743

743-
Object.entries(featuredTracks).forEach(([version, arrayOfTracks]) => {
744-
const errorMessage = `Featured learning track not found for ${version} in ${yamlAbsPath}`
745-
expect(arrayOfTracks.length, errorMessage).toBe(1)
744+
Object.entries(featuredTracks).forEach(([version, numOfFeaturedTracks]) => {
745+
const errorMessage = `Expected one featured learning track for ${version} in ${yamlAbsPath}`
746+
expect(numOfFeaturedTracks, errorMessage).toBe(1)
746747
})
747748
})
748749

0 commit comments

Comments
 (0)