Skip to content

Commit 7db5bb2

Browse files
nzakasmdjermanovic
andauthored
docs: Show prerelease version in dropdown (#18135)
* docs: Show prerelease version in dropdown fixes #17943 * Update docs/src/_data/eslintNextVersion.js Co-authored-by: Milos Djermanovic <[email protected]> * Update docs/src/_includes/components/nav-version-switcher.html Co-authored-by: Milos Djermanovic <[email protected]> * Update versions-list.html --------- Co-authored-by: Milos Djermanovic <[email protected]>
1 parent e462524 commit 7db5bb2

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
"devDependencies": {
2626
"@11ty/eleventy": "^2.0.1",
27+
"@11ty/eleventy-fetch": "^4.0.0",
2728
"@11ty/eleventy-img": "^3.1.1",
2829
"@11ty/eleventy-navigation": "^0.3.5",
2930
"@11ty/eleventy-plugin-rss": "^1.1.1",

docs/src/_data/eslintNextVersion.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @fileoverview
3+
* @author Nicholas C. Zakas
4+
*/
5+
6+
//-----------------------------------------------------------------------------
7+
// Requirements
8+
//-----------------------------------------------------------------------------
9+
10+
const eleventyFetch = require("@11ty/eleventy-fetch");
11+
12+
//-----------------------------------------------------------------------------
13+
// Exports
14+
//-----------------------------------------------------------------------------
15+
16+
module.exports = async function() {
17+
18+
// if we're on the next branch, we can just read the package.json file
19+
if (process.env.BRANCH === "next") {
20+
return require("../../package.json").version;
21+
}
22+
23+
// otherwise, we need to fetch the latest version from the GitHub API
24+
const url = "https://raw.githubusercontent.com/eslint/eslint/next/docs/package.json";
25+
26+
const response = await eleventyFetch(url, {
27+
duration: "1d",
28+
type: "json"
29+
});
30+
31+
return response.version;
32+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<select name="version selector" id="nav-version-select" aria-describedby="nav-version-infobox" class="c-custom-select switcher__select auto-switcher">
1515
<option value="HEAD" data-url="/docs/head/" {% if HEAD %}selected{% endif %}>HEAD</option>
1616
{% if config.showNextVersion == true %}
17-
<option value="NEXT" data-url="/docs/next/" {% if GIT_BRANCH == "next" %}selected{% endif %}>NEXT</option>
17+
<option value="{{ eslintNextVersion }}" data-url="/docs/next/" {% if GIT_BRANCH == "next" %}selected{% endif %}>v{{ eslintNextVersion }}</option>
1818
{% endif %}
1919
<option value="{{ eslintVersion }}" data-url="/docs/latest/" {% if GIT_BRANCH == "latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
2020
{% for version in versions.items %}

docs/src/_includes/components/version-switcher.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<select name="version selector" id="version-select" aria-describedby="version-infobox" class="c-custom-select switcher__select auto-switcher">
1515
<option value="HEAD" data-url="/docs/head/" {% if HEAD %}selected{% endif %}>HEAD</option>
1616
{% if config.showNextVersion == true %}
17-
<option value="NEXT" data-url="/docs/next/" {% if GIT_BRANCH=="next" %}selected{% endif %}>NEXT</option>
17+
<option value="{{ eslintNextVersion }}" data-url="/docs/next/" {% if GIT_BRANCH=="next" %}selected{% endif %}>v{{ eslintNextVersion }}</option>
1818
{% endif %}
1919
<option value="{{ eslintVersion }}" data-url="/docs/latest/" {% if GIT_BRANCH == "latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
2020
{% for version in versions.items %}

docs/src/_includes/partials/versions-list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ul class="versions-list">
22
<li><a href="/docs/head/" {% if HEAD %} data-current="true" {% endif %}>HEAD</a></li>
33
{% if config.showNextVersion == true %}
4-
<li><a href="/docs/next/" {% if GIT_BRANCH == "next" %} data-current="true" {% endif %}>NEXT</a></li>
4+
<li><a href="/docs/next/" {% if GIT_BRANCH == "next" %} data-current="true" {% endif %}>v{{ eslintNextVersion }}</a></li>
55
{% endif %}
66
<li><a href="/docs/latest/" {% if GIT_BRANCH == "latest" %} data-current="true" {% endif %}>v{{ eslintVersion }}</a></li>
77
{%- for version in versions.items -%}

0 commit comments

Comments
 (0)