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: update to sphinx 5.1 #565

Merged
merged 23 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1816c52
deps: update sphinx to 5.0.1
onerandomusername Jun 12, 2022
b8d7752
fix: remove patched searchtools.js
shiftinv Jun 13, 2022
70e3719
fix: replace jquery operations with vanilla js
shiftinv Jun 13, 2022
59c14c0
fix: re-enable `/` search shortcut
shiftinv Jun 13, 2022
a097f33
fix: use correct search summary css selector
shiftinv Jun 13, 2022
bacdf85
chore: update search scorer
shiftinv Jun 13, 2022
df3d721
Merge remote-tracking branch 'upstream/master' into docs/sphinx-5.0
shiftinv Jun 25, 2022
c93a1a9
deps: update sphinx to 5.0.2
shiftinv Jun 25, 2022
682c96f
chore: add unmodified searchtools.js
shiftinv Jun 25, 2022
384f4e2
fix: apply searchtools patch
shiftinv Jun 25, 2022
f95c7ca
revert: "fix: use correct search summary css selector"
shiftinv Jun 25, 2022
4f5489e
fix: fix custom search scorer
shiftinv Jun 25, 2022
b816828
deps: tighten sphinx version requirement
shiftinv Jun 25, 2022
680ff46
deps: update sphinx to 5.1.0
onerandomusername Jul 25, 2022
319a50b
chore: remove now unnecessary type: ignore comment
onerandomusername Jul 25, 2022
4ad4639
Merge branch 'master' into docs/sphinx-5.0
onerandomusername Jul 25, 2022
3f21e63
docs: add changenote
onerandomusername Jul 25, 2022
0fc40e6
fix: don't use deprecated method on docutils.nodes classes
onerandomusername Jul 25, 2022
15535dc
chore: pin and fix sphinx-hoverxref
onerandomusername Jul 26, 2022
0f14d8d
chore: move search shortcuts to the new config location
onerandomusername Jul 26, 2022
65d5e0b
deps: update to 5.1.1
onerandomusername Jul 26, 2022
f906f16
Merge branch 'master' into docs/sphinx-5.0
onerandomusername Jul 26, 2022
2e82412
docs: loosen version in changenotes
onerandomusername Jul 26, 2022
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
1 change: 1 addition & 0 deletions changelog/565.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update sphinx from 4.5.0 to version 5.1, and take advantage of new options.
33 changes: 22 additions & 11 deletions docs/_static/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ let showHideSidebar;
document.addEventListener('DOMContentLoaded', () => {
mobileSearch = new SearchBar();


const search_box = document.querySelector(".search input[type='search']");
const updateSearchPlaceholder = function() {
if (window.matchMedia && window.matchMedia('(max-width: 600px)').matches) {
Expand Down Expand Up @@ -215,25 +214,25 @@ document.addEventListener('DOMContentLoaded', () => {


function focusSearch() {
$('input[name=q]').first().focus();
document.querySelector("input[name=q]")?.focus();
}


function unfocusSearch() {
$('input[name=q]').first().blur();
document.querySelector("input[name=q]")?.blur();
}


$(document).keydown((event) => {
document.addEventListener("keydown", (event) => {
if (event.altKey || event.metaKey)
return;

const focusedElement = document.activeElement;
if (["TEXTAREA", "INPUT", "SELECT", "BUTTON"].includes(focusedElement.tagName)) {
// handle `escape` in search field
if (!event.ctrlKey && !event.shiftKey && event.key === "Escape" && $('input[name=q]').first().is(focusedElement)) {
if (!event.ctrlKey && !event.shiftKey && event.key === "Escape" && document.querySelector("input[name=q]") === focusedElement) {
unfocusSearch();
return false;
return event.preventDefault();
}
// otherwise, ignore all key presses in inputs
return;
Expand All @@ -243,25 +242,37 @@ $(document).keydown((event) => {
// close modal using `escape`, if modal exists
if (event.key === "Escape" && activeModal) {
activeModal.close();
return false;
return event.preventDefault();
}

// focus search using `s` (`/` is already supported by Sphinx)
if (event.key === "s") {
focusSearch();
return false;
return event.preventDefault();
}
}

// focus search using `ctrl+k`
if (!event.shiftKey && event.ctrlKey && event.key == "k") {
focusSearch();
return false;
return event.preventDefault();
}
});

$(document).ready(function () {
$('a.external').attr('target', '_blank');

const _doc_ready = (callback) => {
if (document.readyState !== "loading") {
callback();
} else {
document.addEventListener("DOMContentLoaded", callback);
}
};


_doc_ready(() => {
document.querySelectorAll("a.external").forEach((a) => {
a.setAttribute("target", "_blank");
})
});

var url = new URL(window.location.href);
Expand Down
31 changes: 18 additions & 13 deletions docs/_static/scorer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use-strict';

let queryBeingDone = null;
let pattern = null;
let queryBeingDone = undefined;
let pattern = undefined;

const escapedRegex = /[-\/\\^$*+?.()|[\]{}]/g;
function escapeRegex(e) {
Expand All @@ -23,14 +23,28 @@ function __cleanNamespaces(query) {
return query.replace(/(disnake\.(ext\.)?)?(.+)/, '$3');
}

Scorer = {
function __setPattern() {
const params = new URLSearchParams(window.location.search);
queryBeingDone = params.get('q');
if (queryBeingDone) {
pattern = new RegExp(Array.from(queryBeingDone).map(escapeRegex).join('.*?'), 'i');
} else {
queryBeingDone = null;
pattern = null;
}
}

Scorer = {
// Implement the following function to further tweak the score for each result
// The function takes a result array [filename, title, anchor, descr, score]
// and returns the new score.
score: (result) => {
// only inflate the score of things that are actual API reference things
const [, title, , , score] = result;
const [, title, , , score,] = result;

if (queryBeingDone === undefined) {
__setPattern();
}

if (pattern !== null && title.startsWith('disnake.')) {
let _score = __score(title, pattern);
Expand Down Expand Up @@ -64,12 +78,3 @@ Scorer = {
term: 5,
partialTerm: 2
};

document.addEventListener('DOMContentLoaded', () => {
const params = new URLSearchParams(window.location.search);
queryBeingDone = params.get('q');
if (queryBeingDone) {
let _pattern = Array.from(queryBeingDone).map(escapeRegex).join('.*?');
pattern = new RegExp(_pattern, 'i');
}
});