diff --git a/docs/package.json b/docs/package.json index cb11570a689..5f9030f4e59 100644 --- a/docs/package.json +++ b/docs/package.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@11ty/eleventy": "^2.0.1", + "@11ty/eleventy-fetch": "^4.0.0", "@11ty/eleventy-img": "^3.1.1", "@11ty/eleventy-navigation": "^0.3.5", "@11ty/eleventy-plugin-rss": "^1.1.1", diff --git a/docs/src/_data/eslintNextVersion.js b/docs/src/_data/eslintNextVersion.js new file mode 100644 index 00000000000..d3742364c54 --- /dev/null +++ b/docs/src/_data/eslintNextVersion.js @@ -0,0 +1,32 @@ +/** + * @fileoverview + * @author Nicholas C. Zakas + */ + +//----------------------------------------------------------------------------- +// Requirements +//----------------------------------------------------------------------------- + +const eleventyFetch = require("@11ty/eleventy-fetch"); + +//----------------------------------------------------------------------------- +// Exports +//----------------------------------------------------------------------------- + +module.exports = async function() { + + // if we're on the next branch, we can just read the package.json file + if (process.env.BRANCH === "next") { + return require("../../package.json").version; + } + + // otherwise, we need to fetch the latest version from the GitHub API + const url = "https://raw.githubusercontent.com/eslint/eslint/next/docs/package.json"; + + const response = await eleventyFetch(url, { + duration: "1d", + type: "json" + }); + + return response.version; +} diff --git a/docs/src/_includes/components/nav-version-switcher.html b/docs/src/_includes/components/nav-version-switcher.html index a01e5ddf30c..b070e90a954 100644 --- a/docs/src/_includes/components/nav-version-switcher.html +++ b/docs/src/_includes/components/nav-version-switcher.html @@ -14,7 +14,7 @@ {% if config.showNextVersion == true %} - + {% endif %} {% for version in versions.items %} diff --git a/docs/src/_includes/partials/versions-list.html b/docs/src/_includes/partials/versions-list.html index 7f07e4fa495..2b859eb9c77 100644 --- a/docs/src/_includes/partials/versions-list.html +++ b/docs/src/_includes/partials/versions-list.html @@ -1,7 +1,7 @@