-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Sphinx search with Pagefind (#3186)
Co-authored-by: clydeps <U5yx99dok9> Co-authored-by: Jesse Hills <[email protected]>
- Loading branch information
1 parent
a1910a3
commit dd263f2
Showing
9 changed files
with
215 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ jobs: | |
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Install pagefind | ||
uses: jaxxstorm/[email protected] | ||
with: | ||
repo: cloudcannon/pagefind | ||
- | ||
name: Checkout source code | ||
uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ jobs: | |
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install pagefind | ||
uses: jaxxstorm/[email protected] | ||
with: | ||
repo: cloudcannon/pagefind | ||
- uses: actions/[email protected] | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!-- docs/_templates/search.html --> | ||
{% extends "page.html" %} | ||
|
||
{%- block htmltitle -%} | ||
<title>{{ _("Search") }} - {{ docstitle }}</title> | ||
{%- endblock htmltitle -%} | ||
|
||
{% block content %} | ||
<h1>{{ _("Search") }}</h1> | ||
<div id="search"></div> | ||
{% endblock %} | ||
|
||
{% block scripts -%} | ||
{{ super() }} | ||
{%- endblock scripts %} | ||
|
||
{% block extra_styles -%} | ||
{{ super() }} | ||
<style type="text/css"> | ||
#search form input[type="text"] { | ||
box-sizing: border-box; | ||
width: 100%; | ||
line-height: 2em; | ||
padding-inline: 0.6em; | ||
font-size: 1.2rem; | ||
border-radius: 0.05rem; | ||
border: 2px solid var(--color-foreground-border); | ||
border-bottom-color: 2px solid var(--color-foreground-secondary); | ||
transition: border-color 20ms ease; | ||
} | ||
#search form input[type="text"]:focus { | ||
border-color: var(--color-foreground-primary); | ||
} | ||
</style> | ||
{%- endblock extra_styles %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<script src="/pagefind/pagefind-modular-ui.js"></script> | ||
<div class="pagefind-ui__form" id="search"></div> | ||
<div class="search-results" id="mobile-search-results"></div> | ||
<script> | ||
let callbackAdded = null; | ||
|
||
window.addEventListener('DOMContentLoaded', (event) => { | ||
const std_target = document.getElementById("search-results"); | ||
const mobile_target = document.getElementById("mobile-search-results"); | ||
const inpel = document.getElementById("search"); | ||
|
||
function showTarget() { | ||
var target = std_target; | ||
if (window.innerWidth <= 875) { | ||
target = mobile_target; | ||
std_target.style.display = "none"; | ||
} else { | ||
mobile_target.style.display = "none"; | ||
} | ||
target.style.display = "block"; | ||
const rect = target.getBoundingClientRect(); | ||
const height = window.innerHeight; | ||
target.style.width = "100%"; | ||
target.style.height = "fit-content"; | ||
target.style.maxHeight = (height - rect.top - 10) + "px"; | ||
if (!callbackAdded) { | ||
callbackAdded = true; | ||
document.addEventListener('click', clickCallback); | ||
} | ||
} | ||
|
||
function hideTargets() { | ||
std_target.style.display = "none"; | ||
mobile_target.style.display = "none"; | ||
std_target.style.height = "0"; | ||
mobile_target.style.height = "0"; | ||
if (callbackAdded) { | ||
document.removeEventListener('click', clickCallback); | ||
callbackAdded = false; | ||
} | ||
} | ||
|
||
|
||
const instance = new PagefindModularUI.Instance({ | ||
showSubResults: true, | ||
showImages: false, | ||
ranking: { | ||
pageLength: 0.0, | ||
termSaturation: 1.6, | ||
termFrequency: 0.4, | ||
termSimilarity: 6.0 | ||
} | ||
}); | ||
|
||
instance.add(new PagefindModularUI.Input({ | ||
containerElement: "#search" | ||
})); | ||
|
||
instance.add(new PagefindModularUI.ResultList({ | ||
containerElement: "#search-results" | ||
})); | ||
instance.add(new PagefindModularUI.ResultList({ | ||
containerElement: "#mobile-search-results" | ||
})); | ||
|
||
const clickCallback = (event) => { | ||
const path = event.composedPath(); | ||
if (path.includes(std_target) || path.includes(mobile_target) || path.includes(inpel)) | ||
return; | ||
hideTargets(); | ||
}; | ||
if (std_target && mobile_target) { | ||
instance.on("results", (results) => { | ||
if (results.results.length) { | ||
showTarget(); | ||
} else { | ||
hideTargets(); | ||
} | ||
}); | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
site: _build/html | ||
exclude_selectors: | ||
- "a.headerlink" | ||
- ".toctree-wrapper" | ||
- ".sphinxsidebar" | ||
- ".breadcrumbs" | ||
glob: "{components,cookbook,guides,projects,web-api}/**/*.html" | ||
root_selector: div[role=main] | ||
|