Skip to content

Commit 39e0e0d

Browse files
authored
Use Liquidjs instead of Liquid (#16743)
* Install liquidjs, uninstall liquid * Comment a bunch of stuff out to get going * Fix invalid includes * Fix all includes (path => 'path') * Get the homepage to render * Do link-in-list kinda * Revert "Fix all includes (path => 'path')" This reverts commit d6fead646353aa5041d9229470a62a1d487456b9. * Support non-dynamic partials * Extract getTemplate helper * Do remaining custom Liquid tags * Fix some custom tag bugs * Moar bugs * Re-add link tag * Cleaner diff * Actually fix extended markdown tags * Fully comment out version matchers * Smaller diff * Rely only on Liquid internals for conditionals * Use new operators option in Liquid engine * Fix link.js * Don't need options * Updoot to the right doot * Fix some bugs * Fix another bug * Pass a test * Fix the translate bits * Adjust a test * Fix another invalid Liquid bug * Two more borked translations * Found some more * Don't need this change * Revert "Don't need this change" This reverts commit a916d619747f0492865a69c3e237c97c4d4e7fad. * This should fix the broken links * Missed one * Revert "This should fix the broken links" This reverts commit e6c2cc0d9055d958706260d57edbe293281c150e. * Revert "Missed one" This reverts commit bbe1f23baf16e020f6f7931589decb1afc75dfbd. * Updoot liquidjs
1 parent 0c7e676 commit 39e0e0d

33 files changed

Lines changed: 1423 additions & 1438 deletions

File tree

content/actions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ versions:
6666
</div>
6767

6868
<div class="d-flex flex-wrap gutter">
69-
{% render 'code-example-card' for actionsCodeExamples as example %}
69+
{% render code-example-card for actionsCodeExamples as example %}
7070
</div>
7171

7272
<button class="js-filter-card-show-more btn btn-outline float-right" data-js-filter-card-max="6">Show more {% octicon "arrow-right" %}</button>

content/discussions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ versions:
4040
<h2 class="mb-2 font-mktg h1">Communities using discussions</h2>
4141

4242
<div class="d-flex flex-wrap gutter">
43-
{% render 'discussions-community-card' for discussionsCommunityExamples as example %}
43+
{% render discussions-community-card for discussionsCommunityExamples as example %}
4444
</div>
4545
{% if discussionsCommunityExamples.length > 6 %}
4646
<button class="js-filter-card-show-more btn btn-outline float-right" data-js-filter-card-max="6">Show more {% octicon "arrow-right" %}</button>

layouts/product-landing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ <h2 class="font-mktg h1 mb-2">Guides</h2>
120120

121121
<div class="d-lg-flex gutter-lg flex-items-stretch">
122122
{% assign guideCards = featuredLinks.guideCards %}
123-
{% render "guide-card" for guideCards as guide %}
123+
{% render guide-card for guideCards as guide %}
124124
</div>
125125

126126
<a href="{{ currentPath }}/guides" class="btn btn-outline float-right">Explore guides {% octicon "arrow-right" %}</a>

lib/liquid-tags/data.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
const Liquid = require('liquid')
1+
const { TokenizationError } = require('liquidjs')
22

33
const Syntax = /([a-z0-9/\\_.\-[\]]+)/i
44
const SyntaxHelp = "Syntax Error in 'data' - Valid syntax: data [path]"
55

6-
module.exports = class Data extends Liquid.Tag {
7-
constructor (template, tagName, markup) {
8-
super(template, tagName, markup)
9-
10-
const match = Syntax.exec(markup)
11-
if (!match) {
12-
throw new Liquid.SyntaxError(SyntaxHelp)
6+
module.exports = {
7+
parse (tagToken) {
8+
if (!tagToken || !Syntax.test(tagToken.args)) {
9+
throw new TokenizationError(SyntaxHelp, tagToken)
1310
}
1411

15-
this.path = match[1]
16-
}
12+
this.path = tagToken.args
13+
},
1714

18-
async render (context) {
19-
const value = await context.get(`site.data.${this.path}`)
15+
async render (scope) {
16+
const value = await this.liquid.evalValue(`site.data.${this.path}`, scope)
2017
if (typeof value !== 'string') return value
21-
return this.template.engine.parseAndRender(value, context)
18+
return this.liquid.parseAndRender(value, scope.environments)
2219
}
2320
}

lib/liquid-tags/extended-markdown.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const Liquid = require('liquid')
2-
31
const tags = {
42
mac: '',
53
windows: '',
@@ -13,11 +11,26 @@ const tags = {
1311

1412
const template = '<div class="extended-markdown {{ tagName }} {{ classes }}">{{ output }}</div>'
1513

16-
class ExtendedMarkdown extends Liquid.Block {
17-
async render (context) {
18-
const chunks = await super.render(context)
19-
const output = Liquid.Helpers.toFlatString(chunks)
20-
return this.template.engine.parseAndRender(template, {
14+
const ExtendedMarkdown = {
15+
type: 'block',
16+
17+
parse (tagToken, remainTokens) {
18+
this.tagName = tagToken.name
19+
this.templates = []
20+
21+
const stream = this.liquid.parser.parseStream(remainTokens)
22+
stream
23+
.on(`tag:end${this.tagName}`, () => stream.stop())
24+
.on('template', tpl => this.templates.push(tpl))
25+
.on('end', () => {
26+
throw new Error(`tag ${tagToken.getText()} not closed`)
27+
})
28+
stream.start()
29+
},
30+
31+
render: function * (scope) {
32+
const output = yield this.liquid.renderer.renderTemplates(this.templates, scope)
33+
return yield this.liquid.parseAndRender(template, {
2134
tagName: this.tagName,
2235
classes: tags[this.tagName],
2336
output
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const Link = require('./link')
2-
31
// For details, see class method in lib/liquid-tags/link.js
4-
module.exports = class HomepageLinkWithIntro extends Link {}
2+
const link = require('./link')
3+
module.exports = link('homepage-link-with-intro')

lib/liquid-tags/indented-data-reference.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const Liquid = require('liquid')
21
const assert = require('assert')
32

43
// This class supports a tag that expects two parameters, a data reference and `spaces=NUMBER`:
@@ -10,11 +9,15 @@ const assert = require('assert')
109
// reference is used inside a block element (like a list or nested list) without
1110
// affecting the formatting when the reference is used elsewhere via {{ site.data.foo.bar }}.
1211

13-
module.exports = class IndentedDataReference extends Liquid.Tag {
12+
module.exports = {
13+
parse (tagToken) {
14+
this.markup = tagToken.args.trim()
15+
},
16+
1417
async render (context) {
1518
// obfuscate first legit space, remove all other spaces, then restore legit space
1619
// this way we can support spaces=NUMBER as well as spaces = NUMBER
17-
const input = this.markup.trim()
20+
const input = this.markup
1821
.replace(/\s/, 'REALSPACE')
1922
.replace(/\s/g, '')
2023
.replace('REALSPACE', ' ')
@@ -27,7 +30,7 @@ module.exports = class IndentedDataReference extends Liquid.Tag {
2730
assert(parseInt(numSpaces) || numSpaces === '0', '"spaces=NUMBER" must include a number')
2831

2932
// Get the referenced value from the context
30-
const value = await context.get(dataReference)
33+
const value = await this.liquid.evalValue(dataReference, context)
3134

3235
// If nothing is found in the context, exit with nothing; this may
3336
// feel weird and that we should throw an error, but this is "The Liquid Way TM"
@@ -36,6 +39,6 @@ module.exports = class IndentedDataReference extends Liquid.Tag {
3639
// add spaces to each line
3740
const renderedReferenceWithIndent = value.replace(/^/mg, ' '.repeat(numSpaces))
3841

39-
return this.template.engine.parseAndRender(renderedReferenceWithIndent, context)
42+
return this.liquid.parseAndRender(renderedReferenceWithIndent, context)
4043
}
4144
}
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const Link = require('./link')
1+
const link = require('./link')
2+
const linkAsArticleCard = link('link-as-article-card')
23

34
// For details, see class method in lib/liquid-tags/link.js
4-
module.exports = class LinkAsArticleCard extends Link {
5-
async renderPageProps (page, ctx, props) {
6-
const renderedProps = await super.renderPageProps(page, ctx, props)
7-
const { type: typeKey, topics = [] } = page
8-
const typeVal = typeKey ? ctx.site.data.ui.product_sublanding.guide_types[typeKey] : null
9-
return {
10-
...renderedProps,
11-
type: { key: typeKey, value: typeVal },
12-
topics
13-
}
5+
linkAsArticleCard.renderPageProps = async function renderPageProps (page, ctx, props) {
6+
const renderedProps = await link().renderPageProps(page, ctx, props)
7+
const { type: typeKey, topics = [] } = page
8+
const typeVal = typeKey ? ctx.site.data.ui.product_sublanding.guide_types[typeKey] : null
9+
return {
10+
...renderedProps,
11+
type: { key: typeKey, value: typeVal },
12+
topics
1413
}
1514
}
15+
16+
module.exports = linkAsArticleCard

lib/liquid-tags/link-in-list.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
const Link = require('./link')
2-
3-
// For details, see class method in lib/liquid-tags/link.js
4-
module.exports = class LinkInList extends Link {}
1+
const link = require('./link')
2+
module.exports = link('link-in-list')

lib/liquid-tags/link-with-intro.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const Link = require('./link')
2-
31
// For details, see class method in lib/liquid-tags/link.js
4-
module.exports = class LinkWithIntro extends Link {}
2+
const link = require('./link')
3+
module.exports = link('link-with-intro')

0 commit comments

Comments
 (0)