зеркало из https://github.com/github/docs.git
Rewrite links in Page.intro with language (#16550)
* Add defaultLanguage behavior * Add a million logs because I'm confused * Rewrite intro links * Undo changes to detect-language * Add a test
This commit is contained in:
Родитель
4053c9d59b
Коммит
52dbd92144
|
@ -123,6 +123,12 @@ class Page {
|
|||
|
||||
async _render (context) {
|
||||
this.intro = await renderContent(this.rawIntro, context)
|
||||
|
||||
// rewrite local links in the intro to include current language code and GHE version if needed
|
||||
const introHtml = cheerio.load(this.intro)
|
||||
rewriteLocalLinks(introHtml, context.currentVersion, context.currentLanguage)
|
||||
this.intro = introHtml('body').html()
|
||||
|
||||
this.introPlainText = await renderContent(this.rawIntro, context, { textOnly: true })
|
||||
this.title = await renderContent(this.rawTitle, context, { textOnly: true, encodeEntities: true })
|
||||
this.shortTitle = await renderContent(this.shortTitle, context, { textOnly: true, encodeEntities: true })
|
||||
|
|
|
@ -90,6 +90,21 @@ describe('Page class', () => {
|
|||
expect($(`a[href="/en/${nonEnterpriseDefaultVersion}/articles/about-pull-requests"]`).length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
test('rewrites links in the intro to include the current language prefix and version', async () => {
|
||||
const page = new Page(opts)
|
||||
page.rawIntro = '[Pull requests](/articles/about-pull-requests)'
|
||||
const context = {
|
||||
page: { version: nonEnterpriseDefaultVersion },
|
||||
currentVersion: nonEnterpriseDefaultVersion,
|
||||
currentPath: '/en/github/collaborating-with-issues-and-pull-requests/about-branches',
|
||||
currentLanguage: 'en'
|
||||
}
|
||||
await page.render(context)
|
||||
const $ = cheerio.load(page.intro)
|
||||
expect($('a[href="/articles/about-pull-requests"]').length).toBe(0)
|
||||
expect($(`a[href="/en/${nonEnterpriseDefaultVersion}/articles/about-pull-requests"]`).length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
test('does not rewrite links that include deprecated enterprise release numbers', async () => {
|
||||
const page = new Page({
|
||||
relativePath: 'admin/enterprise-management/migrating-from-github-enterprise-1110x-to-2123.md',
|
||||
|
|
Загрузка…
Ссылка в новой задаче