原生的Butterfly主题首页无法显示字数总计,阅读时长,本文给出配置的方法。

修改主题的_config.yml文件

添加如下内容:

post_meta:
  page: # Home Page
    date_type: both # created or updated or both 主頁文章日期是創建日或者更新日或都顯示
    date_format: date # date/relative 顯示日期還是相對日期
    categories: true # true or false 主頁是否顯示分類
    tags: true # true or false 主頁是否顯示標籤
    label: true # true or false 顯示描述性文字
    # add
    # 首页是否开启字数统计
    wordcount_enable: true
    # 首页是否显示开启阅读数量
    page_pv: true

修改源码

源码位置路径如下

\blog\themes\butterfly\layout\includes\mixins\post-ui.pug

参考的源码为

\blog\themes\butterfly\layout\includes\header\post-info.pug

搜索

mixin countBlockInIndex

在之前添加如下内容:

- let pageWordcount = theme.post_meta.page.wordcount_enable && theme.wordcount.enable && (theme.wordcount.post_wordcount || theme.wordcount.min2read)
if (pageWordcount)
  span.article-meta__separator |
  span.post-meta-wordcount
    if theme.wordcount.post_wordcount
      i.far.fa-file-word.fa-fw.post-meta-icon
      span.post-meta-label= _p('post.wordcount') + ': '
      span.word-count= wordcount(article.content)
      if theme.wordcount.min2read
        span.article-meta__separator |
    if theme.wordcount.min2read
      i.far.fa-clock.fa-fw.post-meta-icon
      span.post-meta-label= _p('post.min2read') + ': '
      span= min2read(article.content, {cn: 350, en: 160}) + _p('post.min2read_unit')