Skip to content

Commit df7768e

Browse files
nzakasmdjermanovic
andauthored
docs: Switch to version-relative URLs (#15978)
* docs: Switch to version-relative URLs Implements /docs/head and /docs/latest as ways to load the docs from the HEAD branch and from the latest release. * Update Makefile.js * Update docs/src/_includes/components/nav-version-switcher.html Co-authored-by: Milos Djermanovic <[email protected]> * Update docs/src/_includes/components/version-switcher.html Co-authored-by: Milos Djermanovic <[email protected]> * Update docs/src/_includes/partials/versions-list.html Co-authored-by: Milos Djermanovic <[email protected]> Co-authored-by: Milos Djermanovic <[email protected]>
1 parent 71bc750 commit df7768e

5 files changed

Lines changed: 30 additions & 6 deletions

File tree

Makefile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ function generatePrerelease(prereleaseId) {
318318
*/
319319
function publishRelease() {
320320
ReleaseOps.publishRelease();
321+
322+
// push to latest branch to trigger docs deploy
323+
exec("git push origin HEAD:latest -f");
324+
321325
publishSite();
322326
}
323327

docs/.eleventy.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,29 @@ const {
1616
module.exports = function(eleventyConfig) {
1717

1818
/*
19-
* The site is loaded from /docs on eslint.org and so we need to adjust
20-
* the path prefix so URLs are evaluated correctly.
19+
* The docs stored in the eslint repo are loaded through eslint.org at
20+
* at /docs/head to show the most recent version of the documentation
21+
* based on the HEAD commit. This gives users a preview of what's coming
22+
* in the next release. This is the way that the site works locally so
23+
* it's easier to see if URLs are broken.
24+
*
25+
* When a release is published, HEAD is pushed to the "latest" branch.
26+
* Netlify deploys that branch as well, and in that case, we want the
27+
* docs to be loaded from /docs/latest on eslint.org.
2128
*
2229
* The path prefix is turned off for deploy previews so we can properly
2330
* see changes before deployed.
2431
*/
25-
const pathPrefix = process.env.CONTEXT === "deploy-preview" ? "" : "/docs";
32+
33+
let pathPrefix = "/docs/head";
34+
35+
if (process.env.CONTEXT === "deploy-preview") {
36+
pathPrefix = "";
37+
} else if (process.env.BRANCH === "latest") {
38+
pathPrefix = "/docs/latest";
39+
}
40+
41+
eleventyConfig.addGlobalData("GIT_BRANCH", process.env.BRANCH);
2642

2743
//------------------------------------------------------------------------------
2844
// Filters

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<span class="label__text">Version</span>
1313
</label>
1414
<select name="version selector" id="nav-version-select" aria-describedby="nav-version-infobox" class="c-custom-select switcher__select auto-switcher">
15-
<option value="{{ eslintVersion }}" selected>v{{ eslintVersion }}</option>
15+
<option value="HEAD" data-url="/docs/head/" {% if GIT_BRANCH !="latest" %}selected{% endif %}>HEAD</option>
16+
<option value="{{ eslintVersion }}" data-url="/docs/latest/" {% if GIT_BRANCH=="latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
1617
{% for version in versions.items %}
1718
<option value="{{ version.number }}"
1819
data-url="{{ version.url }}">

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<span class="label__text">Version</span>
1313
</label>
1414
<select name="version selector" id="version-select" aria-describedby="version-infobox" class="c-custom-select switcher__select auto-switcher">
15-
<option value="{{ eslintVersion }}" selected>v{{ eslintVersion }}</option>
15+
<option value="HEAD" data-url="/docs/head/" {% if GIT_BRANCH != "latest" %}selected{% endif %}>HEAD</option>
16+
<option value="{{ eslintVersion }}" data-url="/docs/latest/" {% if GIT_BRANCH == "latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
1617
{% for version in versions.items %}
1718
<option value="{{ version.number }}"
1819
data-url="{{ version.url }}">
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<ul class="versions-list">
2+
<li><a href="/docs/head/" {% if GIT_BRANCH != "latest" %} data-current="true" {% endif %}>HEAD</a></li>
3+
<li><a href="/docs/latest/" {% if GIT_BRANCH == "latest" %} data-current="true" {% endif %}>v{{ eslintVersion }}</a></li>
24
{%- for version in versions.items -%}
3-
<li><a href="{{ version.url }}" {% if config.version == version.number %} data-current="true" {% endif %}>v{{ version.number }}</a></li>
5+
<li><a href="{{ version.url }}">v{{ version.number }}</a></li>
46
{%- endfor -%}
57
</ul>

0 commit comments

Comments
 (0)