Skip to content

Commit

Permalink
fix: Chinese character counting error in overview page (#1845) (#1846)
Browse files Browse the repository at this point in the history
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
HoshinoSuzumi and autofix-ci[bot] committed Sep 27, 2024
1 parent e37a346 commit 6c97d5c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/client/pages/overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@ function toggleRoute(route: SlideRoute) {
}
function wordCount(str: string) {
return str.match(/[\w`'\-]+/g)?.length || 0
const pattern = /[\w`'\-\u0392-\u03C9\u00C0-\u00FF\u0600-\u06FF\u0400-\u04FF]+|[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF\u3040-\u309F\uAC00-\uD7AF]+/g
const m = str.match(pattern)
let count = 0
if (!m)
return 0
for (let i = 0; i < m.length; i++) {
if (m[i].charCodeAt(0) >= 0x4E00) {
count += m[i].length
}
else {
count += 1
}
}
return count
}
function isElementInViewport(el: HTMLElement) {
Expand Down

0 comments on commit 6c97d5c

Please sign in to comment.