I’m quite new to Hugo and would like to get some more insight on how to create a word counter for a specific area (section) of a post, e.g. a counter for the main article area (without the following bibliography, categories, tags etc.).
Where the total word count (here 1,716 words) only counts the actual article area (section).
Any thought on this would be appreciated
If you use the
.WordCount variable in your theme, you get the total number of words from the current page.
That count doesn’t include the name of the tags or categories (or anything you specify in the front matter for that matter). If it includes the bibliography depends on whether you define those references in the page or in the front matter.
You can also use the
countwords function to count the number of words in a string. So if you can strip the pieces from your content (
.Content) that you’re not interested in, you can get the word count from competing the remaining words. (Hope that makes sense.)
Thanks for the input. Yes, I’m currently using the .
WordCount variable for single post. And as of different single pages can vary a lot in the following bibliography data (length, content) for each entry, I don’t see the front matter way as a viable one.
I was more hoping that I could do something with (A) blocks and split the
.Content in sections and only apply the .
WordCount to the actual content (without the bib) or (B) append a block/single post (seperat with the bib) for each single page to make it look like one page, to get the desired result.