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: Switch to version-relative URLs #15978

Merged
merged 5 commits into from Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions Makefile.js
Expand Up @@ -318,6 +318,10 @@ function generatePrerelease(prereleaseId) {
*/
function publishRelease() {
ReleaseOps.publishRelease();

// push to latest branch to trigger docs deploy
exec("git push origin HEAD:latest -f");

publishSite();
}

Expand Down
22 changes: 19 additions & 3 deletions docs/.eleventy.js
Expand Up @@ -16,13 +16,29 @@ const {
module.exports = function(eleventyConfig) {

/*
* The site is loaded from /docs on eslint.org and so we need to adjust
* the path prefix so URLs are evaluated correctly.
* The docs stored in the eslint repo are loaded through eslint.org at
* at /docs/head to show the most recent version of the documentation
* based on the HEAD commit. This gives users a preview of what's coming
* in the next release. This is the way that the site works locally so
* it's easier to see if URLs are broken.
*
* When a release is published, HEAD is pushed to the "latest" branch.
* Netlify deploys that branch as well, and in that case, we want the
* docs to be loaded from /docs/latest on eslint.org.
*
* The path prefix is turned off for deploy previews so we can properly
* see changes before deployed.
*/
const pathPrefix = process.env.CONTEXT === "deploy-preview" ? "" : "/docs";

let pathPrefix = "/docs/head";

if (process.env.CONTEXT === "deploy-preview") {
pathPrefix = "";
} else if (process.env.BRANCH === "latest") {
pathPrefix = "/docs/latest";
}

eleventyConfig.addGlobalData("GIT_BRANCH", process.env.BRANCH);

//------------------------------------------------------------------------------
// Filters
Expand Down
3 changes: 2 additions & 1 deletion docs/src/_includes/components/nav-version-switcher.html
Expand Up @@ -12,7 +12,8 @@
<span class="label__text">Version</span>
</label>
<select name="version selector" id="nav-version-select" aria-describedby="nav-version-infobox" class="c-custom-select switcher__select auto-switcher">
<option value="{{ eslintVersion }}" selected>v{{ eslintVersion }}</option>
<option value="HEAD" data-url="/docs/head" {% if GIT_BRANCH !="latest" %}selected{% endif %}>HEAD</option>
<option value="{{ eslintVersion }}" data-url="/docs/latest" {% if GIT_BRANCH=="latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
nzakas marked this conversation as resolved.
Show resolved Hide resolved
{% for version in versions.items %}
<option value="{{ version.number }}"
data-url="{{ version.url }}">
Expand Down
3 changes: 2 additions & 1 deletion docs/src/_includes/components/version-switcher.html
Expand Up @@ -12,7 +12,8 @@
<span class="label__text">Version</span>
</label>
<select name="version selector" id="version-select" aria-describedby="version-infobox" class="c-custom-select switcher__select auto-switcher">
<option value="{{ eslintVersion }}" selected>v{{ eslintVersion }}</option>
<option value="HEAD" data-url="/docs/head" {% if GIT_BRANCH != "latest" %}selected{% endif %}>HEAD</option>
<option value="{{ eslintVersion }}" data-url="/docs/latest" {% if GIT_BRANCH == "latest" %}selected{% endif %}>v{{ eslintVersion }}</option>
nzakas marked this conversation as resolved.
Show resolved Hide resolved
{% for version in versions.items %}
<option value="{{ version.number }}"
data-url="{{ version.url }}">
Expand Down
4 changes: 3 additions & 1 deletion docs/src/_includes/partials/versions-list.html
@@ -1,5 +1,7 @@
<ul class="versions-list">
<li><a href="/docs/head" {% if GIT_BRANCH != "latest" %} data-current="true" {% endif %}>HEAD</a></li>
<li><a href="/docs/latest" {% if GIT_BRANCH == "latest" %} data-current="true" {% endif %}>v{{ eslintVersion }}</a></li>
nzakas marked this conversation as resolved.
Show resolved Hide resolved
{%- for version in versions.items -%}
<li><a href="{{ version.url }}" {% if config.version == version.number %} data-current="true" {% endif %}>v{{ version.number }}</a></li>
<li><a href="{{ version.url }}">v{{ version.number }}</a></li>
{%- endfor -%}
</ul>