Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: version selectors synchronization (#18260)
* support vNN.x branches * fetch versions * update `versions.json` during releases * trigger rebuilds on Netlify
- Loading branch information
1 parent
e508800
commit 96607d0
Showing
11 changed files
with
188 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Rebuild Docs Sites | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
paths: | ||
- 'docs/src/_data/versions.json' | ||
|
||
jobs: | ||
rebuild: | ||
name: 'Trigger rebuild on Netlify' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: > | ||
jq -r '.items | map(.branch) | join(",")' docs/src/_data/versions.json | ||
| xargs -I{LIST} curl -X POST -d {} "${{ secrets.NETLIFY_DOCS_BUILD_HOOK }}?trigger_branch={{LIST}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
{ | ||
"lang": "en", | ||
"version": "8.57.0", | ||
"showNextVersion": true | ||
"lang": "en" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @fileoverview Data for version selectors | ||
* @author Milos Djermanovic | ||
*/ | ||
|
||
//----------------------------------------------------------------------------- | ||
// Requirements | ||
//----------------------------------------------------------------------------- | ||
|
||
const eleventyFetch = require("@11ty/eleventy-fetch"); | ||
|
||
//----------------------------------------------------------------------------- | ||
// Exports | ||
//----------------------------------------------------------------------------- | ||
|
||
module.exports = async function() { | ||
|
||
const thisBranch = process.env.BRANCH; | ||
const thisVersion = require("../../package.json").version; | ||
|
||
// Fetch the current list of ESLint versions from the `main` branch on GitHub | ||
const url = "https://raw.githubusercontent.com/eslint/eslint/main/docs/src/_data/versions.json"; | ||
|
||
const data = await eleventyFetch(url, { | ||
duration: "1d", // Cache for local development. Netlify does not keep this cache and will therefore always fetch from GitHub. | ||
type: "json" | ||
}); | ||
|
||
const { items } = data; | ||
|
||
// For initial commit purpose only | ||
if (items.length === 0) { | ||
const localData = require("./versions.json"); | ||
items.push(...localData.items); | ||
} | ||
|
||
let foundItemForThisBranch = false; | ||
|
||
for (const item of items) { | ||
const isItemForThisBranch = item.branch === thisBranch; | ||
|
||
foundItemForThisBranch ||= isItemForThisBranch; | ||
|
||
const isNumberVersion = /^\d/.test(item.version); // `false` for HEAD | ||
|
||
if (isNumberVersion) { | ||
|
||
// Make sure the version is correct | ||
if (isItemForThisBranch) { | ||
item.version = thisVersion; | ||
} | ||
|
||
item.display = `v${item.version}`; | ||
} else { | ||
item.display = item.version; | ||
} | ||
|
||
if (isItemForThisBranch) { | ||
item.selected = true; | ||
} | ||
} | ||
|
||
// Add an empty item if this is not a production branch | ||
if (!foundItemForThisBranch) { | ||
items.unshift({ | ||
version: "", | ||
branch: "", | ||
display: "", | ||
path: "", | ||
selected: true | ||
}) | ||
} | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
{ | ||
"items": [ | ||
{ | ||
"version": "HEAD", | ||
"branch": "main", | ||
"path": "/docs/head/" | ||
}, | ||
{ | ||
"version": "9.0.0-rc.0", | ||
"branch": "next", | ||
"path": "/docs/next/" | ||
}, | ||
{ | ||
"version": "8.57.0", | ||
"branch": "latest", | ||
"path": "/docs/latest/" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
<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 %}>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 -%} | ||
<li><a href="{{ version.url }}">v{{ version.number }}</a></li> | ||
{% for item in eslintVersions.items %} | ||
<li><a href="{{ item.path }}" {% if item.selected %} data-current="true" {% endif %}>{{ item.display }}</a></li> | ||
{%- endfor -%} | ||
</ul> |