diff options
| author | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-30 23:42:13 +0200 |
|---|---|---|
| committer | Serghei Iakovlev <egrep@protonmail.ch> | 2022-07-30 23:42:24 +0200 |
| commit | 56ee7b58bf0261cef6bfefc6ace20dc9e033c5f1 (patch) | |
| tree | 4ad36ecc71cb5acf93e36924d5220dd76a67ea30 | |
| parent | 545c26b7e59a4d8fffb0aa946e440eca78a24887 (diff) | |
| download | gohugo-theme-ed-56ee7b58bf0261cef6bfefc6ace20dc9e033c5f1.tar.gz | |
Correct Regex to match sentence boundary when render search result
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | assets/js/search.js | 3 |
2 files changed, 3 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f2b96e..769534f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix opening external links in new tab/window when use - Google Site Tag tagging/analytics framework + Google Site Tag tagging/analytics framework +- Correct Regex to match sentence boundary when render search result ## [v0.5.0](https://github.com/sergeyklay/gohugo-theme-ed/compare/v0.4.0...v0.5.0) diff --git a/assets/js/search.js b/assets/js/search.js index f37e15b..b66b12d 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -156,8 +156,7 @@ function createSearchResultBlurb(query, pageContent) { // term, we need a way to identify where each sentence begins/ends. This // regex will be used to produce a list of all sentences from the page // content. - const sentenceBoundaryRegex = new RegExp('\\b\\.\\s', 'gm'); - + const sentenceBoundaryRegex = new RegExp(/(?=[^])(?:\P{Sentence_Terminal}|\p{Sentence_Terminal}(?!['"`\p{Close_Punctuation}\p{Final_Punctuation}\s]))*(?:\p{Sentence_Terminal}+['"`\p{Close_Punctuation}\p{Final_Punctuation}]*|$)/, 'gum'); const searchQueryHits = Array.from( pageContent.matchAll(searchQueryRegex), (m) => m.index |
