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 all 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
4 changes: 3 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 @@ -60,6 +61,7 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addGlobalData("HEAD", process.env.BRANCH === "main");
eleventyConfig.addGlobalData("NOINDEX", process.env.BRANCH !== "latest");
eleventyConfig.addGlobalData("PATH_PREFIX", pathPrefix);
eleventyConfig.addGlobalData("is_number_version", isNumberVersion);
eleventyConfig.addDataExtension("yml", contents => yaml.load(contents));

//------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions docs/src/_data/eslintVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = async function() {
const { items } = data;

let foundItemForThisBranch = false;
let isPrereleasePhase = false;

for (const item of items) {
const isItemForThisBranch = item.branch === thisBranch;
Expand All @@ -54,6 +55,10 @@ module.exports = async function() {
if (isItemForThisBranch) {
item.selected = true;
}

if (item.branch === "next") {
isPrereleasePhase = true;
}
}

// Add an empty item if this is not a production branch
Expand All @@ -67,5 +72,7 @@ module.exports = async function() {
});
}

data.isPrereleasePhase = isPrereleasePhase;

return data;
};
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 eslintVersions.isPrereleasePhase 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