0%

Hexo博客版本升级到Next7.8.0

将Hexo博客版本从 hexo v3.7.1 next v5.1.3 升级到 hexo v4.2.1 next v7.8.0 时的一些设置。

Next v5.xNext v7.x 的配置还是有一定差异的。

不蒜子计数统计设置

找到相应配置文件 next/layout/_third-party/statistics/busuanzi-counter.swig

根据 不蒜子 | 不如 官网中的说明,其中:

1
2
3
本站总访问量<span id="busuanzi_value_site_pv"></span>次
本站访客数<span id="busuanzi_value_site_uv"></span>人次
本文总阅读量<span id="busuanzi_value_page_pv"></span>次

上面的三个 id 标签部分就表示要显示的统计内容。

找到 busuanzi-counter.swig 文件中的:

1
2
3
<span class="site-uv" title="{{ __('footer.total_visitors') }}">
<span id="busuanzi_value_site_uv"></span>
</span>

修改为:

1
2
3
<span class="site-uv" title="{{ __('footer.total_visitors') }}">
访客数 <span id="busuanzi_value_site_uv"></span> 人次
</span>

找到:

1
2
3
<span class="site-pv" title="{{ __('footer.total_views') }}">
<span id="busuanzi_value_site_pv"></span>
</span>

修改为:

1
2
3
<span class="site-pv" title="{{ __('footer.total_views') }}">
访问量 <span id="busuanzi_value_site_pv"></span> 次
</span>

即可。


gitalk设置

找到 /next/layout/_third-party/comments/gitalk.swig 文件:

将其中的

1
id : '{{ gitalk_md5(page.path) }}',

修改为:

1
id : '{{ theme.gitalk.id_prefix }}_{{ date(page.date, "YYYYMMDDHHmmss") }}',

然后在 _config.yml 中添加:

1
2
3
4
5
gitalk: 
enable: true
...
id_prefix: itfanr
...

即可。

这里要说明一下,在之前 next v5.1.3 版本中,我设置的 id 值为:

1
id : '{{ theme.gitalk.id_prefix || gitalk }}_{{ date(page.date, "YYYYMMDDHHmmss") }}',

即如果没有在配置文件中设置参数 id_prefix 的话,会默认使用 gitalk 为前缀,在 Next v7.x 中发现这样设置发布时会报错,所以就去掉了默认值。

对于 labels 的显示,可以参考 Error: u.concat(…).join is not a function


博客置顶设置

安装插件:

1
2
npm install hexo-generator-index-pin-top --save
npm uninstall hexo-generator-index --save

修改博客文件目录中的 /themes/next/layout/_macro/post.swig 文件。

找到 <div class="post-meta"> ,在下面添加

1
2
3
4
5
{%- if post.top %}
<i class="fa fa-thumbtack"></i>
<font color='#f05050'>置顶</font>
<span class="post-meta-divider">|</span>
{%- endif %}

然后往上面找到

1
{% elif is_index %}

1
{%- else %}

之间的部分,在

1
2
{%- endif %}
{{ next_url(post.path, post.title or __('post.untitled'), {class: 'post-title-link', itemprop: 'url'}) }}

的中间加上

1
{%- if post.top %}<font color="#f05050">[置顶] </font> {%- endif %}

即:

1
2
3
{%- endif %}
{%- if post.top %}<font color="#f05050">[置顶] </font> {%- endif %}
{{ next_url(post.path, post.title or __('post.untitled'), {class: 'post-title-link', itemprop: 'url'}) }}

然后在需要设置 置顶 的文章头部添加 top: true 即可。


如有疑问或需要技术讨论,请留言或发邮件到 service@itfanr.cc