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

doc: fix the known issues filter script #19664

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 15 additions & 12 deletions doc/_extensions/static/page_filter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function createFilterTags(dropdown, elementType, filterTags) {
var classFilterRE = Object.keys(filterTags);
var index = classFilterRE.indexOf("versions");
if (index !== -1) {
classFilterRE[index] = "v\\d+-\\d+-\\d+";
classFilterRE[index] = "v\\d+-\\d+-\\d+(-[a-zA-Z0-9]+)*";
}
var parentElements = elementType.split("/");
document.querySelectorAll(parentElements.shift()).forEach((element) => {
Expand Down Expand Up @@ -87,18 +87,21 @@ function createFilterTags(dropdown, elementType, filterTags) {

var filterName;
if (className in filterTags) {
spanTag.setAttribute("filter", className);
spanTag.classList.add("filtertag");
filterName = filterTags[className];
}
else if (RegExp('v\\d+-\\d+-\\d+').test(className)) {
aTag.setAttribute("href", URL + "?v=" + className);
spanTag.setAttribute("version", className);
spanTag.classList.add("versiontag");
filterName = className.replace(/v(\d+)-(\d+)-(\d+)/i, 'v$1.$2.$3');
spanTag.setAttribute("filter", className);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff due to extra spaces being added?

spanTag.classList.add("filtertag");
filterName = filterTags[className];
}
else if (RegExp('v\\d+-\\d+-\\d+').test(className)) {
aTag.setAttribute("href", URL + "?v=" + className);
spanTag.setAttribute("version", className);
spanTag.classList.add("versiontag");
// Updated replace method to handle additional segments after vX-X-X
filterName = className.replace(/v(\d+)-(\d+)-(\d+)(-.*)?/, (match, p1, p2, p3, p4) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this regex be used everywhere?

return `v${p1}.${p2}.${p3}${p4 || ''}`;
});
/** When clicking a version tag, filter by the corresponding version **/
spanTag.addEventListener("click", () => displayOption(className, dropdown));
}
}
var textNode = document.createTextNode(filterName);

spanTag.appendChild(textNode);
Expand Down Expand Up @@ -158,7 +161,7 @@ function setupFiltering(name, filterTagContainer=undefined, filterTags={}) {
/** Retrieve the 'v' parameter and switch to that version, if applicable.
Otherwise, switch to the version that is selected in the dropdown. **/
var v = getUrlParameter('v');
if ("versions" in filterTags && (RegExp('v\\d+-\\d+-\\d+').test(v))) {
if ("versions" in filterTags && (RegExp('v\\d+-\\d+-\\d+(-[a-zA-Z0-9]+)*').test(v))) {
displayOption(v, dropdown);
}
else {
Expand Down
Loading