forked from 11ty/11ty-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddedin.js
25 lines (21 loc) · 951 Bytes
/
addedin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const semver = require("semver");
const versions = require("../_data/versions");
module.exports = eleventyConfig => {
eleventyConfig.addShortcode("addedin", function(version, tag, extraClass) {
const newestPublishedVersion = versions.filter(v => v.tag !== "LATEST").shift();
if( typeof version !== "string" ) {
tag = version.tag;
version = version.version;
}
let versionPrefix = "";
let hasBeenReleased = true;
if(("" + version).match(/^[0-9]/)) {
versionPrefix = "v";
// only works for versions starting with a number (plugins don’t do this)
// is the latest version less than or equal to the version being passed in here?
hasBeenReleased = semver.lte(version, semver.coerce(newestPublishedVersion.tag));
}
tag = tag || "span";
return `<${tag} class="minilink minilink-addedin${extraClass ? ` ${extraClass}`: ""}">${hasBeenReleased ? "New in" : "Coming soon in"} ${versionPrefix}${version}</${tag}>`;
});
}