Hexo(sakura)文章增添字数统计和阅读时长功能

一、文章增添字数统计和阅读时长功能

1. 安装hexo-wordcount

先安装相关插件,终端输入以下命令:

npm install hexo-wordcount --save

2. 文件配置(3步)

2.1在theme\sakura\layout\_partial\下创建word.ejs文件(显示样式):

	<div style="margin-top:10px;">
	    <span class="post-time">
	      <span class="post-meta-item-icon">
	        <i class="fa fa-keyboard-o"></i>
	        <span class="post-meta-item-text">  字数统计: </span>
	        <!-- 安装插件npm install hexo-wordcount --save -->
	        <span class="post-count"><%= wordcount(post.content) %>字</span>
	      </span>
	    </span>
	
	    <span class="post-time">
	      &nbsp; | &nbsp;
	      <span class="post-meta-item-icon">
	        <i class="fa fa-hourglass-half"></i>
	        <span class="post-meta-item-text">  阅读时长: </span>
	        <span class="post-count"><%= min2read(post.content) %>分</span>
	      </span>
	    </span>
	</div>

2.2在\themes\sakura\layout\_widget\common-article.ejs文章标题中合适位置添加:(添加在</head>标签前)

		  <!-- 开始添加字数统计-->
	      <% if(theme.word_count && !post.no_word_count){%>
	        <%- partial('_partial/word') %>
	      <% } %>
	      <!-- 添加完成 -->

2.3在MyWeb\themes\sakura\_config.yml配置文末添加:

	# 是否开启字数统计
	#不需要使用,直接设置值为false,或注释掉
	word_count: true
  1. 运行效果由图片所示
    在这里插入图片描述

二、修复作者头像和链接显示问题

在这里插入图片描述
在_post目录写md文章时,应该加上作者信息:
author(名称),authorLink(链接),avatar(头像),authorAbout(简介)

---
title: 2020年2月4日情人节随笔
author: cungudafa
authorLink: https://cungudafa.gitee.io
avatar: https://cdn.jsdelivr.net/gh/cungudafa/cdn/img/custom/cungudafa.jpg
authorAbout: 姑,一个学习记录者
date: 2020-02-13 22:59:10
tag: 随笔
categories: 生活
comment: true
description: 
photos: 
---

\themes\sakura\layout\_widget\common-article.ejs文章标题中可修改样式:

在这里插入图片描述
在这里插入图片描述

发布了203 篇原创文章 · 获赞 352 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/cungudafa/article/details/104308312