-
Notifications
You must be signed in to change notification settings - Fork 7
feat: make pagefind the new default search engine #96
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
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cf4a465
feat: make pagefind the new default search engine
pfitzseb eab6187
set root-selector and exclude-selectors
pfitzseb 7d48b09
fix: use nodejs_jll, use rootpath
pfitzseb 7713a29
chore: use runic instead of JuliaFormatter
pfitzseb 69c633b
chore: formatting, cleanup
pfitzseb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,152 @@ | ||
| #multi-page-nav .search { | ||
| margin-left: auto; | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| #multi-page-nav .search .search-keybinding { | ||
| float: right; | ||
| width: 0; | ||
| transform: translateX(-1em); | ||
| color: #999; | ||
| } | ||
|
|
||
| #multi-page-nav .search:focus-within .search-keybinding { | ||
| display: none; | ||
| } | ||
|
|
||
| #multi-page-nav .search #search-input { | ||
| border: 1px solid #666; | ||
| border-radius: 3.2px; | ||
| color: #999; | ||
| background-color: unset; | ||
| height: 28px; | ||
| font-family: inherit; | ||
| width: 20em; | ||
| font-size: 14px; | ||
| padding: 0 8px; | ||
| } | ||
|
|
||
| #multi-page-nav .search #search-input::placeholder { | ||
| color: #999; | ||
| opacity: 1; | ||
| } | ||
|
|
||
| #multi-page-nav .search:focus-within #search-input { | ||
| background-color: #fff; | ||
| outline: none; | ||
| box-shadow: none; | ||
| color: #000; | ||
| } | ||
|
|
||
| .theme--documenter-dark #multi-page-nav .search:focus-within #search-input { | ||
| background-color: #202227; | ||
| color: #eee; | ||
| } | ||
|
|
||
| #multi-page-nav .search:focus-within .suggestions { | ||
| display: block; | ||
| } | ||
|
|
||
| #multi-page-nav .hidden { | ||
| display: none !important; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestions { | ||
| margin: -5px 1.5rem 0 0; | ||
| display: none; | ||
| background: #fff; | ||
| min-width: 20em; | ||
| max-width: 50vw; | ||
| position: absolute; | ||
| border: 1px solid #cfd4db; | ||
| border-radius: 6px; | ||
| padding: .4rem; | ||
| list-style-type: none; | ||
| z-index: 10; | ||
| right: 0; | ||
| max-height: max(50vh, 250px); | ||
| overflow-y: auto; | ||
| } | ||
|
|
||
| .theme--documenter-dark #multi-page-nav .suggestions { | ||
| background: #2e3138; | ||
| border: 1px solid #5e6d6f; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestions mark { | ||
| background-color: inherit; | ||
| color: #000; | ||
| } | ||
| .theme--documenter-dark #multi-page-nav .suggestions mark { | ||
| color: #fff; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestions .suggestion { | ||
| line-height: 1.3; | ||
| border-radius: 4px; | ||
|
|
||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| word-break: break-all; | ||
| } | ||
| #multi-page-nav .suggestions .sub-suggestions .suggestion { | ||
| margin-left: 1rem; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestions .suggestion-header { | ||
| padding: .4rem .6rem; | ||
| } | ||
| #multi-page-nav .suggestions .suggestion-header:focus-visible { | ||
| outline: none; | ||
| } | ||
| .theme--documenter-dark #multi-page-nav .suggestions .suggestion-header:hover, | ||
| .theme--documenter-dark #multi-page-nav .suggestions .suggestion-header:focus { | ||
| background-color: #202227; | ||
| } | ||
| #multi-page-nav .suggestions .suggestion-header:hover, | ||
| #multi-page-nav .suggestions .suggestion-header:focus { | ||
| background-color: #eee; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestions .suggestion .suggestion-excerpt { | ||
| font-size: small; | ||
| color: #666; | ||
| } | ||
| .theme--documenter-dark #multi-page-nav .suggestions .suggestion .suggestion-excerpt { | ||
| color: #aaa; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestion .suggestion-title { | ||
| font-size: 1.2rem; | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestion .sub-suggestions .suggestion-title { | ||
| font-size: 1rem; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestion a { | ||
| display: block; | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| color: black; | ||
| } | ||
|
|
||
| .theme--documenter-dark #multi-page-nav .suggestion a { | ||
| color: white; | ||
| } | ||
|
|
||
| #multi-page-nav .suggestions .suggestion .page-title { | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| @media screen and (max-width: 1055px) { | ||
| #multi-page-nav .search #search-input { | ||
| width: 100%; | ||
| } | ||
| #multi-page-nav .suggestions { | ||
| max-width: 100vw; | ||
| width: calc(100% - 3.5rem); | ||
| margin: 10px 2.5em 4.5em 0; | ||
| } | ||
| } |
This file contains hidden or 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,150 @@ | ||
| // custom search widget | ||
| (async function() { | ||
| const MAX_RESULTS = 20 | ||
| let FOCUSABLE_ELEMENTS = [] | ||
| let FOCUSED_ELEMENT_INDEX = 0 | ||
|
|
||
| const pagefind = await import("/pagefind/pagefind.js"); | ||
|
|
||
| function initialize() { | ||
| pagefind.init() | ||
| registerSearchListener() | ||
|
|
||
| document.body.addEventListener('keydown', ev => { | ||
| if (document.activeElement === document.body && (ev.key === '/' || ev.key === 's')) { | ||
| document.getElementById('search-input').focus() | ||
| ev.preventDefault() | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| function registerSearchListener() { | ||
| const input = document.getElementById('search-input') | ||
| const suggestions = document.getElementById('search-result-container') | ||
|
|
||
| async function runSearch() { | ||
| const query = input.value | ||
|
|
||
| const search = await pagefind.debouncedSearch(query, {}, 300); | ||
|
|
||
| if (search) { | ||
| buildResults(search.results) | ||
| } | ||
| } | ||
|
|
||
| input.addEventListener('keyup', ev => { | ||
| runSearch() | ||
| }) | ||
|
|
||
| input.addEventListener('keydown', ev => { | ||
| if (ev.key === 'ArrowDown') { | ||
| FOCUSED_ELEMENT_INDEX = 0 | ||
| FOCUSABLE_ELEMENTS[FOCUSED_ELEMENT_INDEX].focus() | ||
| ev.preventDefault() | ||
| return | ||
| } else if (ev.key === 'ArrowUp') { | ||
| FOCUSED_ELEMENT_INDEX = FOCUSABLE_ELEMENTS.length - 1 | ||
| FOCUSABLE_ELEMENTS[FOCUSED_ELEMENT_INDEX].focus() | ||
| ev.preventDefault() | ||
| return | ||
| } | ||
| }) | ||
|
|
||
| suggestions.addEventListener('keydown', ev => { | ||
| if (ev.key === 'ArrowDown') { | ||
| FOCUSED_ELEMENT_INDEX += 1 | ||
| if (FOCUSED_ELEMENT_INDEX < FOCUSABLE_ELEMENTS.length) { | ||
| FOCUSABLE_ELEMENTS[FOCUSED_ELEMENT_INDEX].focus() | ||
| } else { | ||
| FOCUSED_ELEMENT_INDEX = -1 | ||
| input.focus() | ||
| } | ||
| ev.preventDefault() | ||
| } else if (ev.key === 'ArrowUp') { | ||
| FOCUSED_ELEMENT_INDEX -= 1 | ||
| if (FOCUSED_ELEMENT_INDEX >= 0) { | ||
| FOCUSABLE_ELEMENTS[FOCUSED_ELEMENT_INDEX].focus() | ||
| } else { | ||
| FOCUSED_ELEMENT_INDEX = -1 | ||
| input.focus() | ||
| } | ||
| ev.preventDefault() | ||
| } | ||
| }) | ||
|
|
||
| input.addEventListener('focus', ev => { | ||
| runSearch() | ||
| }) | ||
| } | ||
|
|
||
| function renderResult(result) { | ||
| const entry = document.createElement('li') | ||
| entry.classList.add('suggestion') | ||
|
|
||
| const linkContainer = document.createElement('a') | ||
| linkContainer.classList.add('suggestion-header') | ||
| linkContainer.setAttribute('href', result.url) | ||
|
|
||
| const page = document.createElement('p') | ||
| page.classList.add('suggestion-title') | ||
|
|
||
| const pageTitle = document.createElement('span') | ||
| pageTitle.innerText = result.title ?? result.meta.title | ||
|
|
||
| page.appendChild(pageTitle) | ||
|
|
||
| const excerpt = document.createElement('p') | ||
| excerpt.classList.add('suggestion-excerpt') | ||
| excerpt.innerHTML = result.excerpt | ||
|
|
||
| linkContainer.appendChild(page) | ||
| linkContainer.appendChild(excerpt) | ||
|
|
||
| entry.appendChild(linkContainer) | ||
|
|
||
| return entry | ||
| } | ||
|
|
||
| async function buildResults(results) { | ||
| const suggestions = document.getElementById('search-result-container') | ||
|
|
||
| const children = await Promise.all(results.slice(0, MAX_RESULTS - 1).map(async (r, i) => { | ||
| const data = await r.data() | ||
|
|
||
| const entry = renderResult(data) | ||
|
|
||
| if (data.sub_results.length > 0) { | ||
| const subResults = document.createElement('ol') | ||
| subResults.classList.add('sub-suggestions') | ||
|
|
||
| data.sub_results.forEach(subresult => { | ||
| const entry = renderResult(subresult) | ||
| subResults.appendChild(entry) | ||
| }) | ||
| entry.appendChild(subResults) | ||
| } | ||
|
|
||
| return entry | ||
| })) | ||
|
|
||
| if (results.length > 0) { | ||
| suggestions.classList.remove('hidden') | ||
| } else { | ||
| suggestions.classList.add('hidden') | ||
| } | ||
|
|
||
|
|
||
| suggestions.replaceChildren( | ||
| ...children | ||
| ) | ||
|
|
||
| FOCUSED_ELEMENT_INDEX = -1 | ||
| FOCUSABLE_ELEMENTS = [...suggestions.querySelectorAll('a')] | ||
| } | ||
|
|
||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', initialize) | ||
| } else { | ||
| initialize() | ||
| }; | ||
| })() |
This file contains hidden or 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 hidden or 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,35 @@ | ||
| module PageFind | ||
| using NodeJS: NodeJS | ||
| using HypertextLiteral | ||
pfitzseb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function inject_script!(custom_scripts, rootpath) | ||
| pushfirst!(custom_scripts, joinpath("assets", "default", "pagefind_integration.js")) | ||
| pushfirst!(custom_scripts, joinpath("pagefind", "pagefind.js")) | ||
pfitzseb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| function inject_styles!(custom_styles) | ||
| pushfirst!(custom_styles, joinpath("assets", "default", "pagefind.css")) | ||
pfitzseb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| function render() | ||
| return @htl """ | ||
| <div class="search nav-item"> | ||
| <input id="search-input" placeholder="Search everywhere..."> | ||
| <ol id="search-result-container" class="suggestions hidden"> | ||
| </ol> | ||
| <div class="search-keybinding">/</div> | ||
| </div> | ||
| """ | ||
| end | ||
|
|
||
| function build_search_index(root, docs, config, rootpath) | ||
| if !success(`npx pagefind -V`) | ||
pfitzseb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
pfitzseb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| error("pagefind search engine not found. Aborting. Try running `npm install pagefind --global`") | ||
| end | ||
|
|
||
| pattern = "*/{$(join(config.index_versions, ","))}/**/*.{html}" | ||
|
|
||
| run(`npx pagefind --site $(root) --glob $(pattern) --root-selector article --exclude-selectors pre`) | ||
pfitzseb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.