File tree Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change 5
5
const { stripHTML } = require ( 'hexo-util' ) ;
6
6
7
7
const getWordCount = ( post ) => {
8
- const lang = post . lang . toLowerCase ( ) ;
9
8
// post.origin is the original post content of hexo-blog-encrypt
10
9
const content = stripHTML ( post . origin || post . content ) . replace ( / \r ? \n | \r / g, '' ) . replace ( / \s + / g, '' ) ;
11
10
12
11
if ( ! post . wordcount ) {
13
- if ( [ 'zh-cn' , 'zh-hk' , 'zh-tw' ] . includes ( lang ) ) {
14
- post . wordcount = ( content . match ( / [ \u4E00 - \u9FA5 ] / g) || [ ] ) . length ;
15
- } else {
16
- post . wordcount = ( content . replace ( / [ \u4E00 - \u9FA5 ] / g, '' ) . match ( / [ a - z A - Z 0 - 9 _ \u0392 - \u03c9 \u0400 - \u04FF ] + | [ \u4E00 - \u9FFF \u3400 - \u4dbf \uf900 - \ufaff \u3040 - \u309f \uac00 - \ud7af \u0400 - \u04FF ] + | [ \u00E4 \u00C4 \u00E5 \u00C5 \u00F6 \u00D6 ] + | \w + / g) || [ ] ) . length ;
17
- }
12
+ const zhCount = ( content . match ( / [ \u4E00 - \u9FA5 ] / g) || [ ] ) . length ;
13
+ const enCount = ( content . replace ( / [ \u4E00 - \u9FA5 ] / g, '' ) . match ( / [ a - z A - Z 0 - 9 _ \u0392 - \u03c9 \u0400 - \u04FF ] + | [ \u4E00 - \u9FFF \u3400 - \u4dbf \uf900 - \ufaff \u3040 - \u309f \uac00 - \ud7af \u0400 - \u04FF ] + | [ \u00E4 \u00C4 \u00E5 \u00C5 \u00F6 \u00D6 ] + | \w + / g) || [ ] ) . length ;
14
+ post . wordcount = zhCount + enCount
18
15
}
19
16
return post . wordcount ;
20
17
} ;
You can’t perform that action at this time.
0 commit comments