зеркало из https://github.com/github/docs.git
small liquid link tag cleanup (#17280)
* remove unnecessary `render` methods * we don't use `link_with_short_title` anymore * remove `shortTitle` option * remove ink_with_short_title tag test
This commit is contained in:
Родитель
2f03bf7370
Коммит
eaacb54422
|
@ -1 +0,0 @@
|
||||||
<a class="link-title Bump-link--hover no-underline" href="{{ fullPath }}">{{ title }}</a>
|
|
|
@ -63,7 +63,6 @@ Note that link tags will only render links that are available in the current pag
|
||||||
| `{% homepage_link_with_intro /href %}` | The linked page's title and intro, with homepage-specific styling.
|
| `{% homepage_link_with_intro /href %}` | The linked page's title and intro, with homepage-specific styling.
|
||||||
| `{% link_in_list /href %}` | The linked page's title in a list item.
|
| `{% link_in_list /href %}` | The linked page's title in a list item.
|
||||||
| `{% topic_link_in_list /href %}` | The linked map topic's title in a list item (used in category TOCs).
|
| `{% topic_link_in_list /href %}` | The linked map topic's title in a list item (used in category TOCs).
|
||||||
| `{% link_with_short_title /href %}` | The linked page's title, where the title is pulled from the page's `shortTitle` frontmatter.
|
|
||||||
| `{% indented_data_reference site.data.foo.bar spaces=NUMBER %}` | The data reference with the specified number of spaces prepended to each line.
|
| `{% indented_data_reference site.data.foo.bar spaces=NUMBER %}` | The data reference with the specified number of spaces prepended to each line.
|
||||||
|
|
||||||
## Creating tags
|
## Creating tags
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
const Link = require('./link')
|
const Link = require('./link')
|
||||||
|
|
||||||
// For details, see class method in lib/liquid-tags/link.js
|
// For details, see class method in lib/liquid-tags/link.js
|
||||||
module.exports = class HomepageLinkWithIntro extends Link {
|
module.exports = class HomepageLinkWithIntro extends Link {}
|
||||||
async render (context) {
|
|
||||||
return super.parseTemplate(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
const Link = require('./link')
|
const Link = require('./link')
|
||||||
|
|
||||||
// For details, see class method in lib/liquid-tags/link.js
|
// For details, see class method in lib/liquid-tags/link.js
|
||||||
module.exports = class LinkInList extends Link {
|
module.exports = class LinkInList extends Link {}
|
||||||
async render (context) {
|
|
||||||
return super.parseTemplate(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
const Link = require('./link')
|
const Link = require('./link')
|
||||||
|
|
||||||
// For details, see class method in lib/liquid-tags/link.js
|
// For details, see class method in lib/liquid-tags/link.js
|
||||||
module.exports = class LinkWithIntro extends Link {
|
module.exports = class LinkWithIntro extends Link {}
|
||||||
async render (context) {
|
|
||||||
return super.parseTemplate(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
const Link = require('./link')
|
|
||||||
|
|
||||||
// For details, see class method in lib/liquid-tags/link.js
|
|
||||||
module.exports = class LinkWithShortTitle extends Link {
|
|
||||||
async render (context) {
|
|
||||||
return super.parseTemplate(context, { shortTitle: true })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,7 +27,7 @@ module.exports = class Link extends LiquidTag {
|
||||||
super(template, tagName, href.trim())
|
super(template, tagName, href.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseTemplate (context, opts = { shortTitle: false }) {
|
async parseTemplate (context) {
|
||||||
const template = await this.getTemplate()
|
const template = await this.getTemplate()
|
||||||
|
|
||||||
const ctx = context.environments[0]
|
const ctx = context.environments[0]
|
||||||
|
@ -64,9 +64,7 @@ module.exports = class Link extends LiquidTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
// find and render the props
|
// find and render the props
|
||||||
const title = opts.shortTitle
|
const title = await page.renderProp('title', ctx, { textOnly: true, encodeEntities: true })
|
||||||
? await page.renderProp('shortTitle', ctx, { textOnly: true, encodeEntities: true })
|
|
||||||
: await page.renderProp('title', ctx, { textOnly: true, encodeEntities: true })
|
|
||||||
|
|
||||||
// we want markdown in intros to be parsed, so we do not pass textOnly here
|
// we want markdown in intros to be parsed, so we do not pass textOnly here
|
||||||
const intro = await page.renderProp('intro', ctx, { unwrap: true })
|
const intro = await page.renderProp('intro', ctx, { unwrap: true })
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
const Link = require('./link')
|
const Link = require('./link')
|
||||||
|
|
||||||
// For details, see class method in lib/liquid-tags/link.js
|
// For details, see class method in lib/liquid-tags/link.js
|
||||||
module.exports = class TopicLinkInList extends Link {
|
module.exports = class TopicLinkInList extends Link {}
|
||||||
async render (context) {
|
|
||||||
return super.parseTemplate(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ renderContent.liquid.registerTag('link_with_intro', require('../liquid-tags/link
|
||||||
renderContent.liquid.registerTag('homepage_link_with_intro', require('../liquid-tags/homepage-link-with-intro'))
|
renderContent.liquid.registerTag('homepage_link_with_intro', require('../liquid-tags/homepage-link-with-intro'))
|
||||||
renderContent.liquid.registerTag('link_in_list', require('../liquid-tags/link-in-list'))
|
renderContent.liquid.registerTag('link_in_list', require('../liquid-tags/link-in-list'))
|
||||||
renderContent.liquid.registerTag('topic_link_in_list', require('../liquid-tags/topic-link-in-list'))
|
renderContent.liquid.registerTag('topic_link_in_list', require('../liquid-tags/topic-link-in-list'))
|
||||||
renderContent.liquid.registerTag('link_with_short_title', require('../liquid-tags/link-with-short-title'))
|
|
||||||
renderContent.liquid.registerTag('indented_data_reference', require('../liquid-tags/indented-data-reference'))
|
renderContent.liquid.registerTag('indented_data_reference', require('../liquid-tags/indented-data-reference'))
|
||||||
renderContent.liquid.registerTag('data', require('../liquid-tags/data'))
|
renderContent.liquid.registerTag('data', require('../liquid-tags/data'))
|
||||||
renderContent.liquid.registerTag('octicon', require('../liquid-tags/octicon'))
|
renderContent.liquid.registerTag('octicon', require('../liquid-tags/octicon'))
|
||||||
|
|
|
@ -79,13 +79,6 @@ describe('liquid helper tags', () => {
|
||||||
expect(output).toBe(expected)
|
expect(output).toBe(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('link_with_short_title tag', async () => {
|
|
||||||
const template = '{% link_with_short_title /contributing-and-collaborating-using-github-desktop %}'
|
|
||||||
const expected = '<a class="link-title Bump-link--hover no-underline" href="/en/desktop/contributing-and-collaborating-using-github-desktop">Contributing and collaborating</a>'
|
|
||||||
const output = await liquid.parseAndRender(template, context)
|
|
||||||
expect(output).toBe(expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('indented_data_reference tag', () => {
|
describe('indented_data_reference tag', () => {
|
||||||
test('without any number of spaces specified', async () => {
|
test('without any number of spaces specified', async () => {
|
||||||
const template = '{% indented_data_reference site.data.reusables.example %}'
|
const template = '{% indented_data_reference site.data.reusables.example %}'
|
||||||
|
|
Загрузка…
Ссылка в новой задаче