Skip to content

Commit 6c97d5c

Browse files
fix: Chinese character counting error in overview page (#1845) (#1846)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent e37a346 commit 6c97d5c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/client/pages/overview.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,20 @@ function toggleRoute(route: SlideRoute) {
4949
}
5050
5151
function wordCount(str: string) {
52-
return str.match(/[\w`'\-]+/g)?.length || 0
52+
const pattern = /[\w`'\-\u0392-\u03C9\u00C0-\u00FF\u0600-\u06FF\u0400-\u04FF]+|[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF\u3040-\u309F\uAC00-\uD7AF]+/g
53+
const m = str.match(pattern)
54+
let count = 0
55+
if (!m)
56+
return 0
57+
for (let i = 0; i < m.length; i++) {
58+
if (m[i].charCodeAt(0) >= 0x4E00) {
59+
count += m[i].length
60+
}
61+
else {
62+
count += 1
63+
}
64+
}
65+
return count
5366
}
5467
5568
function isElementInViewport(el: HTMLElement) {

0 commit comments

Comments
 (0)