iblh / hexo-theme-material

Material Design theme for hexo.
https://iblh.github.io/material-demo/
GNU General Public License v3.0
4.03k stars 564 forks source link

希望添加Word-Counter #707

Open Suyaming97 opened 6 years ago

Suyaming97 commented 6 years ago

I certify that I have first consulted (check all with "x")

我确认我已经查看了 (使用 "x" 选择)


I'm submitting a (check one with "x")

我正在申请 (使用 "x" 选择)

希望添加Word-Counter,我尝试自己添加,参考了网上很多教程,但是都是失败了,希望作者能添加一下,或者给我一点这方面的参考,谢谢。

NS-Sp4ce commented 5 years ago

首先,cd到你的blog目录,然后执行npm i --save hexo-wordcount, 修改文件 hexo\blog\themes\material\layout\_partial\Paradox-post-info.ejs 部分内容如下

        <% if(theme.wordcount.enable === true) { %>
        |
        <i class="material-icons">keyboard</i><span class="post-count">本文共:<%= wordcount(page.content) %>字</span>
        |
        <i class="material-icons">query_builder</i><span class="post-count">阅读时间≈<%= min2read(page.content) %>分</span>
        |
        <% } %>
        <!-- Favorite -->
        <!--
        <button id="article-functions-like-button" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon btn-like">
            <i class="material-icons" role="presentation">favorite</i>
            <span class="visuallyhidden">favorites</span>
        </button>
    -->

hexo\blog\themes\material\layout\_partial\footer.ejs部分内容如下

        <% if(theme.busuanzi.all_site_uv === true) { %>
    <!-- All Site UV -->
    <br />
    <span id="busuanzi_container_site_uv">本站访客数
        <span id="busuanzi_value_site_uv">
        </span>
    </span>|
    <span id="busuanzi_container_site_pv">本站总访问量
        <span id="busuanzi_value_site_pv">

        </span>
    </span>|
    <i class="material-icons">keyboard</i>站点总字数<span class="post-count"><%= totalcount(site) %></span>
    <% } %>
    </div>

    <!-- Paradox Footer Right Section -->
    <!--
        I am glad you use this theme, the development is no so easy, I hope you can keep the copyright.
        It will not impact the appearance and can give developers a lot of support :)

        很高兴您使用该主题,开发不易,希望您可以保留一下版权声明。
        它不会影响美观并可以给开发者很大的支持。 :)
        -->

\hexo\blog\themes\material\_config.yml文件末尾添加内容如下

#wordcount
wordcount:
    enable: true

然后在blog目录执行 hexo g查看效果