Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Show prerelease version in dropdown #18139

Merged
merged 1 commit into from Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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