diff --git a/docs/api/pulsar.md b/docs/api/pulsar.md index 1762d78..21a8fb7 100644 --- a/docs/api/pulsar.md +++ b/docs/api/pulsar.md @@ -2,7 +2,7 @@ title: Pulsar API layout: doc.ejs includeTemplate: - - latest_pulsar_version + - pulsar_versions --- The Pulsar API is what makes Pulsar so incredibly customizable. All packages consume it, including the packages built into the editor. diff --git a/helpers/index.js b/helpers/index.js index 292eabb..47b8487 100644 --- a/helpers/index.js +++ b/helpers/index.js @@ -1,6 +1,8 @@ - // View helpers. Available in EJS templates via the `helpers` namespace. +const fs = require("fs"); +const semver = require("semver"); + module.exports = { nextAndPreviousSidebarEntries(url, sidebar) { let prev = null, next = null; @@ -12,5 +14,33 @@ module.exports = { if (index < lastIndex) next = sidebar[index + 1]; } return [prev, next]; + }, + + getAllPulsarVersions() { + // Returns an array of Pulsar semver versions, in order, and without 'latest' + + let verArr = []; + + const verDocs = fs.readdirSync("./pulsar-api/content"); + + for (const doc of verDocs) { + let clean = doc.replace(".json", ""); + + let name = clean; + + if (!name.startsWith("v")) { + name = "v" + name; + } + + verArr.push({ + name: name, + link: clean + }); + } + + // Sort version array in order + verArr.sort((a, b) => { return semver.rcompare(a.name, b.name); }); + + return verArr; } }; diff --git a/layouts/latest_pulsar_version.ejs b/layouts/latest_pulsar_version.ejs deleted file mode 100644 index 6fc0e83..0000000 --- a/layouts/latest_pulsar_version.ejs +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/layouts/pulsar_versions.ejs b/layouts/pulsar_versions.ejs new file mode 100644 index 0000000..1140803 --- /dev/null +++ b/layouts/pulsar_versions.ejs @@ -0,0 +1,31 @@ + +<% + const pulsarApiVersions = helpers.getAllPulsarVersions(); +-%> + +