使Hexo自动从摘要中提取 description🔨

一段代码使 Hexo 自动从文章more标签处提取description标签内容。

前言

平时水的那么多文章,最近去百度搜索自己的网页,发现很多文章都是下图的样子,仔细检查发现,原来是主题里不支持从<!--more-->标签里自动提取description的内容。

 hexo 自动提取 description

解决方法如下。

代码

将以下代码写入博客主题的head.ejs里即可。

1
2
3
4
5
6
7
<%
let description;
const re = /<[^>]+>|\n|"/gim; if(is_post()) {
description = page.description || page.excerpt.replace(re, '');
}
description = description || theme.description || config.description;
%>

然后在适当位置,写入description
各大主题不同,写的位置不同。