eoghan edits + changed dir structure

This commit is contained in:
Ollie Ballinger
2023-04-17 11:28:29 +01:00
parent 6c5816d659
commit 7ccf85e48e
653 changed files with 44167 additions and 4363 deletions

View File

@@ -45,7 +45,7 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
// highlight matches on the page
if (query !== null && mainEl) {
// perform any highlighting
highlight(query, mainEl);
highlight(escapeRegExp(query), mainEl);
// fix up the URL to remove the q query param
const replacementUrl = new URL(window.location);
@@ -80,23 +80,20 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
// the media query since we generate different HTML for sidebar overlays than we do
// for sidebar input UI)
const detachedMediaQuery =
quartoSearchOptions.type === "overlay"
? "all"
: quartoSearchOptions.location === "navbar"
? "(max-width: 991px)"
: "none";
quartoSearchOptions.type === "overlay" ? "all" : "(max-width: 991px)";
// If configured, include the analytics client to send insights
const plugins = configurePlugins(quartoSearchOptions);
let lastState = null;
const { setIsOpen } = autocomplete({
const { setIsOpen, setQuery, setCollections } = autocomplete({
container: searchEl,
detachedMediaQuery: detachedMediaQuery,
defaultActiveItemId: 0,
panelContainer: "#quarto-search-results",
panelPlacement: quartoSearchOptions["panel-placement"],
debug: false,
openOnFocus: true,
plugins,
classNames: {
form: "d-flex",
@@ -280,6 +277,10 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
}
},
getItems({ query }) {
if (query === null || query === "") {
return [];
}
const limit = quartoSearchOptions.limit;
if (quartoSearchOptions.algolia) {
return algoliaSearch(query, limit, quartoSearchOptions.algolia);
@@ -299,9 +300,15 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
},
templates: {
noResults({ createElement }) {
const hasQuery = lastState.query;
return createElement(
"div",
{ class: "quarto-search-no-results" },
{
class: `quarto-search-no-results${
hasQuery ? "" : " no-query"
}`,
},
language["search-no-results-text"]
);
},
@@ -361,6 +368,12 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
},
});
window.quartoOpenSearch = () => {
setIsOpen(false);
setIsOpen(true);
focusSearchInput();
};
// Remove the labeleledby attribute since it is pointing
// to a non-existent label
if (quartoSearchOptions.type === "overlay") {
@@ -976,6 +989,10 @@ function clearHighlight(searchterm, el) {
}
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}
// highlight matches
function highlight(term, el) {
const termRegex = new RegExp(term, "ig");