9

Hugo中添加字数显示

 3 years ago
source link: https://note.qidong.name/2017/06/24/hugo-word-count/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Hugo中添加字数显示

2017-06-24 23:50:50 +08  字数:424  标签: Hugo

孤想要在页面里显示日期的地方,同时显示字数。

于是,孤找到了Hugo的所有模板变量。

Hugo的模板变量

作为一个静态网站生成器,Hugo提供了网页相关的变量,供模板文件使用。

  • Page Variables
  • Page Params
  • Param method
  • Taxonomy Terms Page Variables
  • Site Variables
  • File Variables
  • Hugo Variables

详见:Hugo - Template Variables

孤需要的内容,就在Page Variables中。 并且,这里列出的内容,对孤有了更多启发。

FuzzyWordCount与WordCount

.FuzzyWordCount The approximate number of words in the content. .WordCount The number of words in the content

其中,.FuzzyWordCount是一个模糊的数字,按每100字向上取整。 比如,1个字算100,2个字也算100,111个字算200。 这对于读者的用户体验,应该是一种优化。 但对孤这个作者来说,就不太合适了。

孤还是直接用.WordCount了,没必要自己骗自己嘛。

实现

既然Hugo已经提供了支持,那么实现就非常简单了。

<span class="post-date">
	{{ .Date }}
	字数:{{ .WordCount }}
</span>

layouts/_default/single.htmllayouts/index.html同时修改。



本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可,详见本站版权声明

本站没有任何支持评论功能的计划。 如果你对本站的设计、内容、观点有什么意见,欢迎来信指正。


作者:匿蟒 邮箱:[email protected] 备案:闽ICP备15022549号


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK