Skip to content

Commit

Permalink
docs: Show prerelease version in dropdown (#18135)
Browse files Browse the repository at this point in the history
* docs: Show prerelease version in dropdown

fixes #17943

* Update docs/src/_data/eslintNextVersion.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update docs/src/_includes/components/nav-version-switcher.html

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update versions-list.html

---------

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
nzakas and mdjermanovic committed Feb 22, 2024
1 parent e462524 commit 7db5bb2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/package.json
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions 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;
}
2 changes: 1 addition & 1 deletion docs/src/_includes/components/nav-version-switcher.html
Expand Up @@ -14,7 +14,7 @@
<select name="version selector" id="nav-version-select" aria-describedby="nav-version-infobox" class="c-custom-select switcher__select auto-switcher">
<option value="HEAD" data-url="/docs/head/" {% if HEAD %}selected{% endif %}>HEAD</option>
{% if config.showNextVersion == true %}
<option value="NEXT" data-url="/docs/next/" {% if GIT_BRANCH == "next" %}selected{% endif %}>NEXT</option>
<option value="{{ eslintNextVersion }}" data-url="/docs/next/" {% if GIT_BRANCH == "next" %}selected{% endif %}>v{{ eslintNextVersion }}</option>
{% endif %}
<option value="{{ eslintVersion }}" data-url="/docs/latest/" {% if GIT_BRANCH == "latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
{% for version in versions.items %}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/_includes/components/version-switcher.html
Expand Up @@ -14,7 +14,7 @@
<select name="version selector" id="version-select" aria-describedby="version-infobox" class="c-custom-select switcher__select auto-switcher">
<option value="HEAD" data-url="/docs/head/" {% if HEAD %}selected{% endif %}>HEAD</option>
{% if config.showNextVersion == true %}
<option value="NEXT" data-url="/docs/next/" {% if GIT_BRANCH=="next" %}selected{% endif %}>NEXT</option>
<option value="{{ eslintNextVersion }}" data-url="/docs/next/" {% if GIT_BRANCH=="next" %}selected{% endif %}>v{{ eslintNextVersion }}</option>
{% endif %}
<option value="{{ eslintVersion }}" data-url="/docs/latest/" {% if GIT_BRANCH == "latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
{% for version in versions.items %}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/_includes/partials/versions-list.html
@@ -1,7 +1,7 @@
<ul class="versions-list">
<li><a href="/docs/head/" {% if HEAD %} data-current="true" {% endif %}>HEAD</a></li>
{% if config.showNextVersion == true %}
<li><a href="/docs/next/" {% if GIT_BRANCH == "next" %} data-current="true" {% endif %}>NEXT</a></li>
<li><a href="/docs/next/" {% if GIT_BRANCH == "next" %} data-current="true" {% endif %}>v{{ eslintNextVersion }}</a></li>
{% endif %}
<li><a href="/docs/latest/" {% if GIT_BRANCH == "latest" %} data-current="true" {% endif %}>v{{ eslintVersion }}</a></li>
{%- for version in versions.items -%}
Expand Down

0 comments on commit 7db5bb2

Please sign in to comment.