-
Notifications
You must be signed in to change notification settings - Fork 72
Improve search. #1111
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
Improve search. #1111
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9c1a30a
Search for mobile and mobile menu styles.
nikoshell 97541a2
Merge branch 'ep2025' into ep2025-search
nikoshell 1bf0884
Fix css style for search modal.
nikoshell 94b8ecd
Add BODY to the EuroPython.
nikoshell 09efdcb
Remove twins.
nikoshell 6106d88
Create separate layout for markdown pages.
nikoshell 606038d
Separate search styles.
nikoshell b95093a
Improve search modal style.
nikoshell 3e4d3b7
Create modal component, add local FA icons.
nikoshell 79f0d13
Merge branch 'ep2025' into ep2025-search
nikoshell b0571c6
Merge branch 'ep2025' into ep2025-search
nikoshell 8464089
New modal variant with close on outside click.
nikoshell 3fb3a74
Prevent body scolling when modal is open.
nikoshell 77e393d
Merge branch 'ep2025' into ep2025-search
egeakman 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
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
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,154 @@ | ||
| --- | ||
| import SearchComponent from "astro-pagefind/components/Search"; | ||
| import Button from "@ui/Button.astro"; | ||
|
|
||
| --- | ||
|
|
||
| <div class="search-wrapper hidden" style="display: none;"> | ||
|
|
||
| <div class="search-header flex items-center justify-between z-40 h-0 md:h-[85px] m-auto "> | ||
| <h2 class="text-black text-4xl ml-10 top-[46px] md:top-[85px]">Search<h2/> | ||
| <Button | ||
| id="search-close" | ||
| clear | ||
| icon="close" | ||
| iconSize="fa-xl" | ||
| class="w-[3em] h-[3em] top-[46px] md:top-[85px]" | ||
| /> | ||
nikoshell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| <div class="modal__overlay"></div> | ||
|
|
||
| <SearchComponent | ||
| id="search" | ||
| className="pagefind-ui" | ||
| uiOptions={{ | ||
| showImages: false, | ||
| translations: { | ||
| zero_results: "Couldn't find [SEARCH_TERM]", | ||
| }, | ||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| <script> | ||
| document.addEventListener("DOMContentLoaded", function () { | ||
| const searchWrapper = document.querySelector(".search-wrapper") as HTMLElement | null; | ||
| const searchContainer = document.querySelector(".pagefind-ui") as HTMLElement | null; | ||
| const searchInput = searchContainer?.querySelector("input") as HTMLInputElement | null; | ||
| const closeButton = document.querySelector("#search-close") as HTMLElement | null; | ||
| const searchButton = document.getElementById("searchButton") as HTMLElement | null; | ||
|
|
||
| let selectedIndex = -1; | ||
|
|
||
| function openSearch() { | ||
| if (searchWrapper) { | ||
| searchWrapper.style.display = "block"; | ||
| if (searchInput) { | ||
| searchInput.value = "Tips"; | ||
| const inputEvent = new Event("input", { bubbles: true }); | ||
| searchInput.dispatchEvent(inputEvent); | ||
| setTimeout(() => { | ||
| searchInput.value = ""; | ||
| searchInput.placeholder = "Tips for You"; | ||
| }, 100); | ||
| searchInput.focus(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function closeSearch() { | ||
| if (searchWrapper) { | ||
| searchWrapper.style.display = "none"; | ||
| selectedIndex = -1; | ||
| } | ||
| } | ||
|
|
||
| function updateSelection() { | ||
| const results = searchContainer?.querySelectorAll(".pagefind-ui__result"); | ||
| if (!results) return; | ||
|
|
||
| results.forEach((result, index) => { | ||
| if (result instanceof HTMLElement) { | ||
| if (index === selectedIndex) { | ||
| result.classList.add("selected"); | ||
| result.scrollIntoView({ block: "nearest", behavior: "smooth" }); | ||
| } else { | ||
| result.classList.remove("selected"); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function makeResultsClickable() { | ||
| const results = searchContainer?.querySelectorAll(".pagefind-ui__result"); | ||
| if (!results) return; | ||
|
|
||
| results.forEach((result) => { | ||
| const link = result.querySelector(".pagefind-ui__result-link") as HTMLAnchorElement | null; | ||
| if (link && !result.hasAttribute("data-clickable")) { | ||
| if (result instanceof HTMLElement) { | ||
| result.style.cursor = "pointer"; | ||
| result.addEventListener("click", (e) => { | ||
| if (!(e.target instanceof HTMLElement) || !e.target.closest("a")) { | ||
| link.click(); | ||
| } | ||
| }); | ||
| result.setAttribute("data-clickable", "true"); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| if (searchButton && searchWrapper) { | ||
| searchButton.addEventListener("click", openSearch); | ||
| } | ||
|
|
||
| document.addEventListener("keydown", function (event) { | ||
| if (!searchContainer || !searchInput) return; | ||
|
|
||
| const results = searchContainer.querySelectorAll(".pagefind-ui__result"); | ||
|
|
||
| if (event.ctrlKey && event.key === "k") { | ||
| event.preventDefault(); | ||
| openSearch(); | ||
| } else if (event.key === "Escape") { | ||
| closeSearch(); | ||
| } else if (document.activeElement === searchInput) { | ||
| if (event.key === "ArrowDown") { | ||
| event.preventDefault(); | ||
| selectedIndex = (selectedIndex + 1) % results.length; | ||
| updateSelection(); | ||
| } else if (event.key === "ArrowUp") { | ||
| event.preventDefault(); | ||
| selectedIndex = (selectedIndex - 1 + results.length) % results.length; | ||
| updateSelection(); | ||
| } else if (event.key === "Enter") { | ||
| event.preventDefault(); | ||
| if (results.length > 0) { | ||
| const indexToOpen = selectedIndex === -1 ? 0 : selectedIndex; | ||
| const link = results[indexToOpen]?.querySelector("a") as HTMLAnchorElement | null; | ||
| link?.click(); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| const resultsObserver = new MutationObserver(() => { | ||
| const results = searchContainer?.querySelectorAll(".pagefind-ui__result"); | ||
| if (results && results.length > 0) { | ||
| selectedIndex = 0; | ||
| updateSelection(); | ||
| makeResultsClickable(); | ||
| } | ||
| }); | ||
|
|
||
| if (searchContainer) { | ||
| resultsObserver.observe(searchContainer, { | ||
| childList: true, | ||
| subtree: true, | ||
| }); | ||
| } | ||
|
|
||
| closeButton?.addEventListener("click", closeSearch); | ||
| }); | ||
| </script> | ||
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.