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
This commit is contained in:
@@ -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: enterprise-server@2.22 => 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: enterprise-server@2.22 => 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
|
||||
|
||||
@@ -1,42 +1,11 @@
|
||||
const Liquid = require('liquid')
|
||||
const semver = require('semver')
|
||||
const { Liquid, defaultOperators } = require('liquidjs')
|
||||
const path = require('path')
|
||||
const engine = new Liquid.Engine()
|
||||
engine.registerFileSystem(
|
||||
new Liquid.LocalFileSystem(path.join(process.cwd(), 'includes'))
|
||||
)
|
||||
const semver = require('semver')
|
||||
|
||||
// GHE versions are not valid SemVer, but can be coerced...
|
||||
// https://github.com/npm/node-semver#coercion
|
||||
|
||||
Liquid.Condition.operators.ver_gt = (cond, left, right) => {
|
||||
if (!matchesVersionString(left)) return false
|
||||
if (!matchesVersionString(right)) return false
|
||||
|
||||
const [leftPlan, leftRelease] = splitVersion(left)
|
||||
const [rightPlan, rightRelease] = splitVersion(right)
|
||||
|
||||
if (leftPlan !== rightPlan) return false
|
||||
|
||||
return semver.gt(semver.coerce(leftRelease), semver.coerce(rightRelease))
|
||||
}
|
||||
|
||||
Liquid.Condition.operators.ver_lt = (cond, left, right) => {
|
||||
if (!matchesVersionString(left)) return false
|
||||
if (!matchesVersionString(right)) return false
|
||||
|
||||
const [leftPlan, leftRelease] = splitVersion(left)
|
||||
const [rightPlan, rightRelease] = splitVersion(right)
|
||||
|
||||
if (leftPlan !== rightPlan) return false
|
||||
|
||||
return semver.lt(semver.coerce(leftRelease), semver.coerce(rightRelease))
|
||||
}
|
||||
|
||||
module.exports = engine
|
||||
|
||||
function matchesVersionString (input) {
|
||||
return input && input.match(/^(?:[a-z](?:[a-z-]*[a-z])?@)?\d+(?:\.\d+)*/)
|
||||
return typeof input === 'string' && input.match(/^(?:[a-z](?:[a-z-]*[a-z])?@)?\d+(?:\.\d+)*/)
|
||||
}
|
||||
// Support new version formats where version = plan@release
|
||||
// e.g., enterprise-server@2.21, where enterprise-server is the plan and 2.21 is the release
|
||||
@@ -59,3 +28,36 @@ function splitVersion (version) {
|
||||
|
||||
return [plan, release]
|
||||
}
|
||||
|
||||
const engine = new Liquid({
|
||||
root: path.join(process.cwd(), 'includes'),
|
||||
extname: '.html',
|
||||
dynamicPartials: false,
|
||||
operators: {
|
||||
...defaultOperators,
|
||||
ver_gt: (left, right) => {
|
||||
if (!matchesVersionString(left)) return false
|
||||
if (!matchesVersionString(right)) return false
|
||||
|
||||
const [leftPlan, leftRelease] = splitVersion(left)
|
||||
const [rightPlan, rightRelease] = splitVersion(right)
|
||||
|
||||
if (leftPlan !== rightPlan) return false
|
||||
|
||||
return semver.gt(semver.coerce(leftRelease), semver.coerce(rightRelease))
|
||||
},
|
||||
ver_lt: (left, right) => {
|
||||
if (!matchesVersionString(left)) return false
|
||||
if (!matchesVersionString(right)) return false
|
||||
|
||||
const [leftPlan, leftRelease] = splitVersion(left)
|
||||
const [rightPlan, rightRelease] = splitVersion(right)
|
||||
|
||||
if (leftPlan !== rightPlan) return false
|
||||
|
||||
return semver.lt(semver.coerce(leftRelease), semver.coerce(rightRelease))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = engine
|
||||
|
||||
@@ -21,7 +21,7 @@ const inlineTagRegex = new RegExp(`\n?(</?${inlineTagString}>?)\n?`, 'gm')
|
||||
|
||||
// parse multiple times because some templates contain more templates. :]
|
||||
module.exports = async function renderContent (
|
||||
template,
|
||||
template = '',
|
||||
context = {},
|
||||
options = {}
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user