Skip to content

Commit 2df63db

Browse files
authored
repo sync
2 parents 473e48a + 52dbd92 commit 2df63db

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/page.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ class Page {
123123

124124
async _render (context) {
125125
this.intro = await renderContent(this.rawIntro, context)
126+
127+
// rewrite local links in the intro to include current language code and GHE version if needed
128+
const introHtml = cheerio.load(this.intro)
129+
rewriteLocalLinks(introHtml, context.currentVersion, context.currentLanguage)
130+
this.intro = introHtml('body').html()
131+
126132
this.introPlainText = await renderContent(this.rawIntro, context, { textOnly: true })
127133
this.title = await renderContent(this.rawTitle, context, { textOnly: true, encodeEntities: true })
128134
this.shortTitle = await renderContent(this.shortTitle, context, { textOnly: true, encodeEntities: true })

tests/unit/page.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ describe('Page class', () => {
9090
expect($(`a[href="/en/${nonEnterpriseDefaultVersion}/articles/about-pull-requests"]`).length).toBeGreaterThan(0)
9191
})
9292

93+
test('rewrites links in the intro to include the current language prefix and version', async () => {
94+
const page = new Page(opts)
95+
page.rawIntro = '[Pull requests](/articles/about-pull-requests)'
96+
const context = {
97+
page: { version: nonEnterpriseDefaultVersion },
98+
currentVersion: nonEnterpriseDefaultVersion,
99+
currentPath: '/en/github/collaborating-with-issues-and-pull-requests/about-branches',
100+
currentLanguage: 'en'
101+
}
102+
await page.render(context)
103+
const $ = cheerio.load(page.intro)
104+
expect($('a[href="/articles/about-pull-requests"]').length).toBe(0)
105+
expect($(`a[href="/en/${nonEnterpriseDefaultVersion}/articles/about-pull-requests"]`).length).toBeGreaterThan(0)
106+
})
107+
93108
test('does not rewrite links that include deprecated enterprise release numbers', async () => {
94109
const page = new Page({
95110
relativePath: 'admin/enterprise-management/migrating-from-github-enterprise-1110x-to-2123.md',

0 commit comments

Comments
 (0)