Hugo | Wrong Wordcount with Chinese in Posts (#.WordCount)
isnanx commented on 30 Apr 2019
Hi, as I write both Chinese and English in my posts, I found it that Chinese characters were not included when counting the words, I doubt if there is something wrong of my usage or it’s truly not supported by now, any reference? Thanks.
Solution Found
It’s really simple. Just configure the value of hasCJKLanguage
to true
(default is false
).
hasCJKLanguage
Default value: false
If true, auto-detect Chinese/Japanese/Korean Languages in the content. This will make
.Summary
and.WordCount
behave correctly for CJK languages.
See: Configure Hugo | Hugo (gohugo.io)
When we work with strings in Hugo, we often want to get some basic information like its length. We can then show that information in our theme for readers or use it with other string operations. Let’s see how we can measure the length of text in Hugo.