diff options
author | coderzh <pythonzh@gmail.com> | 2015-09-03 18:22:20 +0800 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2015-09-12 15:41:17 +0200 |
commit | 0e1fd78fb22e8a870ff3a922f36a9a4d0475c090 (patch) | |
tree | 48a0a74ba70aaf33bcc9f9d1d48576109500ae94 /hugolib | |
parent | c7521b3d672b8d857bfe698f021c498dd27226c9 (diff) |
WordCount Summary support UTF-8 string
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/page.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/hugolib/page.go b/hugolib/page.go index b80e92257..c50e2da18 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -31,6 +31,7 @@ import ( "strings" "sync" "time" + "unicode/utf8" "github.com/spf13/cast" bp "github.com/spf13/hugo/bufferpool" @@ -362,7 +363,16 @@ func (p *Page) ReadFrom(buf io.Reader) (int64, error) { } func (p *Page) analyzePage() { - p.WordCount = len(p.PlainWords()) + p.WordCount = 0 + for _, word := range p.PlainWords() { + runeCount := utf8.RuneCountInString(word) + if len(word) == runeCount { + p.WordCount++ + } else { + p.WordCount += runeCount + } + } + p.FuzzyWordCount = int((p.WordCount+100)/100) * 100 p.ReadingTime = int((p.WordCount + 212) / 213) } |