forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Learning Track navigation banner (github#17440)
* add middleware to handle `learn` query param * add exception to query-less cache key * add querystring to learning track guides
- Loading branch information
1 parent
97dfb49
commit 9bc90cd
Showing
10 changed files
with
176 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="py-3 px-4 rounded bg-white border-gradient--purple-pink d-flex flex-justify-between learning-track-nav"> | ||
{% assign track = currentLearningTrack %} | ||
|
||
<span class="d-flex flex-column"> | ||
{% if track.prevGuide %} | ||
<span class="f6 text-gray">{% data ui.learning_track_nav.prevGuide %}</span> | ||
<a href="{{track.prevGuide.href}}?learn={{track.trackName}}" class="text-bold text-gray">{{track.prevGuide.title}}</a> | ||
{% endif %} | ||
</span> | ||
|
||
<span class="d-flex flex-column flex-items-end"> | ||
{% if track.nextGuide %} | ||
<span class="f6 text-gray">{% data ui.learning_track_nav.nextGuide %}</span> | ||
<a href="{{track.nextGuide.href}}?learn={{track.trackName}}" class="text-bold text-gray text-right">{{track.nextGuide.title}}</a> | ||
{% endif %} | ||
</span> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { getPathWithoutLanguage, getPathWithoutVersion } = require('../lib/path-utils') | ||
const getLinkData = require('../lib/get-link-data') | ||
|
||
module.exports = async (req, res, next) => { | ||
const noTrack = () => { | ||
req.context.currentLearningTrack = {} | ||
return next() | ||
} | ||
|
||
if (!req.context.page) return next() | ||
|
||
const trackName = req.query.learn | ||
if (!trackName) return noTrack() | ||
|
||
const track = req.context.site.data['learning-tracks'][req.context.currentProduct][trackName] | ||
if (!track) return noTrack() | ||
|
||
const currentLearningTrack = { trackName } | ||
|
||
const guidePath = getPathWithoutLanguage(getPathWithoutVersion(req.path)) | ||
const guideIndex = track.guides.findIndex((path) => path === guidePath) | ||
|
||
if (guideIndex < 0) return noTrack() | ||
|
||
if (guideIndex > 0) { | ||
const prevGuidePath = track.guides[guideIndex - 1] | ||
const { href, title } = await getLinkData(prevGuidePath, req.context, { title: true, intro: false }) | ||
currentLearningTrack.prevGuide = { href, title } | ||
} | ||
|
||
if (guideIndex < track.guides.length - 1) { | ||
const nextGuidePath = track.guides[guideIndex + 1] | ||
const { href, title } = await getLinkData(nextGuidePath, req.context, { title: true, intro: false }) | ||
currentLearningTrack.nextGuide = { href, title } | ||
} | ||
|
||
req.context.currentLearningTrack = currentLearningTrack | ||
|
||
return next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const { getDOM } = require('../helpers/supertest') | ||
|
||
jest.setTimeout(3 * 60 * 1000) | ||
|
||
describe('learning tracks', () => { | ||
test('render first track as feature track', async () => { | ||
const $ = await getDOM('/en/actions/guides') | ||
expect($('.feature-track')).toHaveLength(1) | ||
const href = $('.feature-track li a').first().attr('href') | ||
const found = href.match(/.*\?learn=(.*)/i) | ||
expect(found).not.toBeNull() | ||
const trackName = found[1] | ||
|
||
// check all the links contain track name | ||
$('.feature-track li a').each((i, elem) => { | ||
expect($(elem).attr('href')).toEqual(expect.stringContaining(`?learn=${trackName}`)) | ||
}) | ||
}) | ||
|
||
test('render other tracks', async () => { | ||
const $ = await getDOM('/en/actions/guides') | ||
expect($('.learning-track').length).toBeGreaterThanOrEqual(4) | ||
$('.learning-track').each((i, trackElem) => { | ||
const href = $(trackElem).find('.Box-header a').first().attr('href') | ||
const found = href.match(/.*\?learn=(.*)/i) | ||
expect(found).not.toBeNull() | ||
const trackName = found[1] | ||
|
||
// check all the links contain track name | ||
$(trackElem).find('a.Box-row').each((i, elem) => { | ||
expect($(elem).attr('href')).toEqual(expect.stringContaining(`?learn=${trackName}`)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('navigation banner', () => { | ||
test('render navigation banner when url includes correct learning track name', async () => { | ||
const $ = await getDOM('/en/actions/guides/setting-up-continuous-integration-using-workflow-templates?learn=continuous_integration') | ||
expect($('.learning-track-nav')).toHaveLength(1) | ||
const $navLinks = $('.learning-track-nav a') | ||
expect($navLinks).toHaveLength(2) | ||
$navLinks.each((i, elem) => { | ||
expect($(elem).attr('href')).toEqual(expect.stringContaining('?learn=continuous_integration')) | ||
}) | ||
}) | ||
|
||
test('does not include banner when url does not include `learn` param', async () => { | ||
const $ = await getDOM('/en/actions/guides/setting-up-continuous-integration-using-workflow-templates') | ||
expect($('.learning-track-nav')).toHaveLength(0) | ||
}) | ||
|
||
test('does not include banner when url has incorrect `learn` param', async () => { | ||
const $ = await getDOM('/en/actions/guides/setting-up-continuous-integration-using-workflow-templates?learn=not_real') | ||
expect($('.learning-track-nav')).toHaveLength(0) | ||
}) | ||
|
||
test('does not include banner when url is not part of the learning track', async () => { | ||
const $ = await getDOM('/en/actions/learn-github-actions/introduction-to-github-actions?learn=continuous_integration') | ||
expect($('.learning-track-nav')).toHaveLength(0) | ||
}) | ||
}) |