8000 gh-115317: Rewrite changelog filter to use vanilla JavaScript by hugovk · Pull Request #115324 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115317: Rewrite changelog filter to use vanilla JavaScript #115324

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 7 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Format with Prettier
  • Loading branch information
hugovk committed Feb 12, 2024
commit a92636429e056e79cbb6432c640ebffde7f40711
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
root = true

[*.{py,c,cpp,h,rst,md,yml}]
[*.{py,c,cpp,h,js,rst,md,yml}]
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
Expand All @@ -11,5 +11,5 @@ indent_size = 4
[*.rst]
indent_size = 3

[*.yml]
[*.{js,yml}]
indent_size = 2
105 changes: 54 additions & 51 deletions Doc/tools/static/changelog_search.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
document.addEventListener('DOMContentLoaded', function() {
// add the search form and bind the events
document.querySelector('h1').insertAdjacentHTML('afterend', [
'<p>Filter entries by content:',
'<input type="text" value="" id="searchbox" style="width: 50%">',
'<input type="submit" id="searchbox-submit" value="Filter"></p>'
].join('\n'));
document.addEventListener("DOMContentLoaded", function () {
// add the search form and bind the events
document
.querySelector("h1")
.insertAdjacentHTML(
"afterend",
[
"<p>Filter entries by content:",
'<input type="text" value="" id="searchbox" style="width: 50%">',
'<input type="submit" id="searchbox-submit" value="Filter"></p>',
].join("\n"),
);

function dofilter() {
let query;
try {
query = new RegExp(document.querySelector('#searchbox').value, 'i');
}
catch (e) {
return; // not a valid regex (yet)
function dofilter() {
let query;
try {
query = new RegExp(document.querySelector("#searchbox").value, "i");
} catch (e) {
return; // not a valid regex (yet)
}
// find headers for the versions (What's new in Python X.Y.Z?)
const h2s = document.querySelectorAll("#changelog h2");
for (const h2 of h2s) {
let sections_found = 0;
// find headers for the sections (Core, Library, etc.)
const h3s = h2.parentNode.querySelectorAll("h3");
for (let h3 of h3s) {
let entries_found = 0;
// find all the entries
const lis = h3.parentNode.querySelectorAll("li");
for (let li of lis) {
// check if the query matches the entry
if (query.test(li.textContent)) {
li.style.display = "block";
entries_found++;
} else {
li.style.display = "none";
}
}
// find headers for the versions (What's new in Python X.Y.Z?)
const h2s = document.querySelectorAll('#changelog h2');
for(const h2 of h2s) {
let sections_found = 0;
// find headers for the sections (Core, Library, etc.)
const h3s = h2.parentNode.querySelectorAll('h3');
for(let h3 of h3s) {
let entries_found = 0;
// find all the entries
const lis = h3.parentNode.querySelectorAll('li');
for(let li of lis) {
// check if the query matches the entry
if (query.test(li.textContent)) {
li.style.display = 'block';
entries_found++;
}
else {
li.style.display = 'none';
}
}
// if there are entries, show the section, otherwise hide it
if (entries_found > 0) {
h3.parentNode.style.display = 'block';
sections_found++;
}
else {
h3.parentNode.style.display = 'none';
}
}
if (sections_found > 0) {
h2.parentNode.style.display = 'block';
}
else {
h2.parentNode.style.display = 'none';
}
// if there are entries, show the section, otherwise hide it
if (entries_found > 0) {
h3.parentNode.style.display = "block";
sections_found++;
} else {
h3.parentNode.style.display = "none";
}
}
if (sections_found > 0) {
h2.parentNode.style.display = "block";
} else {
h2.parentNode.style.display = "none";
}
}
document.querySelector('#searchbox').addEventListener('keyup', dofilter);
document.querySelector('#searchbox-submit').addEventListener('click', dofilter);
}
document.querySelector("#searchbox").addEventListener("keyup", dofilter);
document
.querySelector("#searchbox-submit")
.addEventListener("click", dofilter);
});
0