Skip to content

Commit

Permalink
fix(search): work around with Intl.Segmenter on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
Octobug committed Nov 4, 2023
1 parent 45a6025 commit 693f528
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .vitepress/theme/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export function tokenize(text: string): Array<string> {
// Firefox doesn't support Intl.Segmenter currently
if (!("Segmenter" in Intl)) {
return text.split(" ");
}

// @ts-ignore: seems like Intl.Segmenter is not supported by the lang server
const segmenter = new Intl.Segmenter("cn", { granularity: "word" });
const words = Array.from(segmenter.segment(text)).map(
Expand Down

0 comments on commit 693f528

Please sign in to comment.