Skip to content

Commit

Permalink
preview site: multiword search
Browse files Browse the repository at this point in the history
To search for multiple words, separate them with a space. Highlighting also works with multiple words.
  • Loading branch information
kamijin-fanta committed Jan 11, 2024
1 parent 9d5d0df commit ff36189
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/preview-astro/src/components/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ export function SearchPageComponent() {
}, []);

if (!isFirstRender && query?.length > 2) {
const hightlightPattern = new RegExp(`(${query})`, "i");
const hightlightPattern = new RegExp(
`(${query
.split(" ")
.filter((t) => !!t)
.join("|")})`,
"i",
);
return (
<>
<IconDetailModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export function SearchIconSet({

const found =
icons &&
Object.keys(icons).filter((name) => name.toLowerCase().includes(query));
Object.keys(icons).filter((name) =>
query
.toLowerCase()
.split(" ")
.filter((t) => !!t)
.every((term) => name.toLowerCase().includes(term)),
);
return (
<>
{found ? (
Expand Down

0 comments on commit ff36189

Please sign in to comment.