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.
Use Liquidjs instead of Liquid (github#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
- Loading branch information
Showing
33 changed files
with
1,423 additions
and
1,438 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
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 |
---|---|---|
@@ -1,23 +1,20 @@ | ||
const Liquid = require('liquid') | ||
const { TokenizationError } = require('liquidjs') | ||
|
||
const Syntax = /([a-z0-9/\\_.\-[\]]+)/i | ||
const SyntaxHelp = "Syntax Error in 'data' - Valid syntax: data [path]" | ||
|
||
module.exports = class Data extends Liquid.Tag { | ||
constructor (template, tagName, markup) { | ||
super(template, tagName, markup) | ||
|
||
const match = Syntax.exec(markup) | ||
if (!match) { | ||
throw new Liquid.SyntaxError(SyntaxHelp) | ||
module.exports = { | ||
parse (tagToken) { | ||
if (!tagToken || !Syntax.test(tagToken.args)) { | ||
throw new TokenizationError(SyntaxHelp, tagToken) | ||
} | ||
|
||
this.path = match[1] | ||
} | ||
this.path = tagToken.args | ||
}, | ||
|
||
async render (context) { | ||
const value = await context.get(`site.data.${this.path}`) | ||
async render (scope) { | ||
const value = await this.liquid.evalValue(`site.data.${this.path}`, scope) | ||
if (typeof value !== 'string') return value | ||
return this.template.engine.parseAndRender(value, context) | ||
return this.liquid.parseAndRender(value, scope.environments) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
const Link = require('./link') | ||
|
||
// For details, see class method in lib/liquid-tags/link.js | ||
module.exports = class HomepageLinkWithIntro extends Link {} | ||
const link = require('./link') | ||
module.exports = link('homepage-link-with-intro') |
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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
const Link = require('./link') | ||
const link = require('./link') | ||
const linkAsArticleCard = link('link-as-article-card') | ||
|
||
// For details, see class method in lib/liquid-tags/link.js | ||
module.exports = class LinkAsArticleCard extends Link { | ||
async renderPageProps (page, ctx, props) { | ||
const renderedProps = await super.renderPageProps(page, ctx, props) | ||
const { type: typeKey, topics = [] } = page | ||
const typeVal = typeKey ? ctx.site.data.ui.product_sublanding.guide_types[typeKey] : null | ||
return { | ||
...renderedProps, | ||
type: { key: typeKey, value: typeVal }, | ||
topics | ||
} | ||
linkAsArticleCard.renderPageProps = async function renderPageProps (page, ctx, props) { | ||
const renderedProps = await link().renderPageProps(page, ctx, props) | ||
const { type: typeKey, topics = [] } = page | ||
const typeVal = typeKey ? ctx.site.data.ui.product_sublanding.guide_types[typeKey] : null | ||
return { | ||
...renderedProps, | ||
type: { key: typeKey, value: typeVal }, | ||
topics | ||
} | ||
} | ||
|
||
module.exports = linkAsArticleCard |
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
const Link = require('./link') | ||
|
||
// For details, see class method in lib/liquid-tags/link.js | ||
module.exports = class LinkInList extends Link {} | ||
const link = require('./link') | ||
module.exports = link('link-in-list') |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
const Link = require('./link') | ||
|
||
// For details, see class method in lib/liquid-tags/link.js | ||
module.exports = class LinkWithIntro extends Link {} | ||
const link = require('./link') | ||
module.exports = link('link-with-intro') |
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
const Link = require('./link') | ||
|
||
// For details, see class method in lib/liquid-tags/link.js | ||
module.exports = class TopicLinkInList extends Link {} | ||
const link = require('./link') | ||
module.exports = link('topic-link-in-list') |
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 |
---|---|---|
|
@@ -3,8 +3,7 @@ const renderContent = require('./renderContent') | |
const { ExtendedMarkdown, tags } = require('../liquid-tags/extended-markdown') | ||
|
||
// Include custom tags like {% link_with_intro /article/foo %} | ||
renderContent.liquid.registerTag('liquid_tag', require('../liquid-tags/liquid-tag')) | ||
renderContent.liquid.registerTag('link', require('../liquid-tags/link')) | ||
renderContent.liquid.registerTag('link', require('../liquid-tags/link')('link')) | ||
renderContent.liquid.registerTag('link_with_intro', require('../liquid-tags/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')) | ||
|
@@ -19,29 +18,29 @@ for (const tag in tags) { | |
renderContent.liquid.registerTag(tag, ExtendedMarkdown) | ||
} | ||
|
||
renderContent.liquid.registerFilters({ | ||
/** | ||
* Like the `size` filter, but specifically for | ||
* getting the number of keys in an object | ||
*/ | ||
obj_size: (input) => { | ||
if (!input) return 0 | ||
return Object.keys(input).length | ||
}, | ||
/** | ||
* Returns the version number of a GHES version string | ||
* ex: [email protected] => 2.22 | ||
*/ | ||
version_num: (input) => { | ||
return input.split('@')[1] | ||
}, | ||
/** | ||
* Convert the input to a slug | ||
*/ | ||
slugify: (input) => { | ||
const slugger = new GithubSlugger() | ||
return slugger.slug(input) | ||
} | ||
/** | ||
* Like the `size` filter, but specifically for | ||
* getting the number of keys in an object | ||
*/ | ||
renderContent.liquid.registerFilter('obj_size', input => { | ||
if (!input) return 0 | ||
return Object.keys(input).length | ||
}) | ||
|
||
/** | ||
* Returns the version number of a GHES version string | ||
* ex: [email protected] => 2.22 | ||
*/ | ||
renderContent.liquid.registerFilter('version_num', input => { | ||
return input.split('@')[1] | ||
}) | ||
|
||
/** | ||
* Convert the input to a slug | ||
*/ | ||
renderContent.liquid.registerFilter('slugify', input => { | ||
const slugger = new GithubSlugger() | ||
return slugger.slug(input) | ||
}) | ||
|
||
module.exports = renderContent |
Oops, something went wrong.