Skip to content

docs: Edit this page button link to different branches #19228

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

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ module.exports = function(eleventyConfig) {
*/

let pathPrefix = "/docs/head/";
const isNumberVersion = process.env.BRANCH && /^v\d+\.x$/u.test(process.env.BRANCH);

if (process.env.CONTEXT === "deploy-preview") {
pathPrefix = "/";
} else if (process.env.BRANCH === "latest") {
pathPrefix = "/docs/latest/";
} else if (process.env.BRANCH === "next") {
pathPrefix = "/docs/next/";
} else if (process.env.BRANCH && /^v\d+\.x$/u.test(process.env.BRANCH)) {
} else if (isNumberVersion) {
pathPrefix = `/docs/${process.env.BRANCH}/`; // `/docs/v8.x/`, `/docs/v9.x/`, `/docs/v10.x/` ...
}

Expand All @@ -55,11 +56,23 @@ module.exports = function(eleventyConfig) {
// Load site-specific data
const siteName = process.env.ESLINT_SITE_NAME || "en";

/**
* Determines whether we are in the prerelease phase.
* @returns {Promise<boolean>} `true` if there is a prerelease of the next major version, `false` otherwise.
*/
async function isPrereleasePhase() {
const eslintVersions = await require("./src/_data/eslintVersions")();

return eslintVersions.items.some(item => item.branch === "next");
}

eleventyConfig.addGlobalData("site_name", siteName);
eleventyConfig.addGlobalData("GIT_BRANCH", process.env.BRANCH);
eleventyConfig.addGlobalData("HEAD", process.env.BRANCH === "main");
eleventyConfig.addGlobalData("NOINDEX", process.env.BRANCH !== "latest");
eleventyConfig.addGlobalData("PATH_PREFIX", pathPrefix);
eleventyConfig.addGlobalData("is_prerelease_phase", isPrereleasePhase);
eleventyConfig.addGlobalData("is_number_version", isNumberVersion);
eleventyConfig.addDataExtension("yml", contents => yaml.load(contents));

//------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/src/_data/sites/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ footer:

edit_link:
start_with: https://github.com/eslint/eslint/edit/main/docs/
start_with_latest: https://github.com/eslint/eslint/edit/latest/docs/
text: Edit this page
1 change: 1 addition & 0 deletions docs/src/_data/sites/zh-hans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ footer:

edit_link:
start_with: https://github.com/eslint/eslint/edit/main/docs/
start_with_latest: https://github.com/eslint/eslint/edit/latest/docs/
text: 编辑此页
8 changes: 7 additions & 1 deletion docs/src/_includes/layouts/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ <h1>{{ title }}</h1>
{% if edit_link %}
{{ edit_link }}
{% else %}
{{ site.edit_link.start_with }}{{ page.inputPath }}
{% if is_prerelease_phase and GIT_BRANCH === 'latest' %}
{{ site.edit_link.start_with_latest }}{{ page.inputPath }}
{% elseif is_number_version %}
https://github.com/eslint/eslint/edit/{{ GIT_BRANCH }}/docs/{{ page.inputPath }}
{% else %}
{{ site.edit_link.start_with }}{{ page.inputPath }}
{% endif %}
{% endif %}
"
class="c-btn c-btn--secondary">{{ site.edit_link.text }}</a>
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy