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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user