* 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
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
const { Liquid, defaultOperators } = require('liquidjs')
|
|
const path = require('path')
|
|
const semver = require('semver')
|
|
|
|
// GHE versions are not valid SemVer, but can be coerced...
|
|
// https://github.com/npm/node-semver#coercion
|
|
function matchesVersionString (input) {
|
|
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
|
|
// e.g., free-pro-team@latest, where free-pro-team is the plan and latest is the release
|
|
// in addition to legacy formats where the version passed is simply 2.21
|
|
function splitVersion (version) {
|
|
// The default plan when working with versions is "enterprise-server".
|
|
// Default to that value here to support backward compatibility from before
|
|
// plans were explicitly included.
|
|
let plan = 'enterprise-server'
|
|
let release
|
|
|
|
const lastIndex = version.lastIndexOf('@')
|
|
if (lastIndex === -1) {
|
|
release = version
|
|
} else {
|
|
plan = version.slice(0, lastIndex)
|
|
release = version.slice(lastIndex + 1)
|
|
}
|
|
|
|
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
|