Welcome to Sanhai’s Blogs!

快速开始

根据搜索结果,安知鱼(AnZhiYu) 是一款基于 Hexo 框架的博客主题。要在该主题中添加"最后更新时间"功能,我给你提供以下技术方案:

实现方案

方案一:在文章 Front-matter 中添加更新时间

在每篇 Markdown 文章的头部添加 updated 字段:

Yaml

title: 文章标题
date: 2026-01-01 10:00:00
updated: 2026-05-16 11:30:00 # 最后更新时间

然后在主题配置文件中启用显示:

Yaml

_config.anzhiyu.yml

post_meta:
updated: true # 显示更新时间

方案二:使用 Hexo 自动生成更新时间插件

安装插件
Bash
npm install hexo-generator-update --save
配置插件 在 Hexo 根目录的 _config.yml 中添加:

1
2
3
4
update_generator:
enable: true
name: 'updated'
default_value: ''

修改主题模板 在 themes/anzhiyu/layouts/_partial/post-meta.pug 中添加:

1
2
3
4
- if post.updated
.post-meta-item
i.fa.fa-clock-o
| 更新时间:#{date(post.updated, 'YYYY-MM-DD HH:mm')}

方案三:手动修改主题文件显示更新时间

找到文章元信息模板文件
themes/anzhiyu/layouts/_partial/post-meta.pug

添加更新时间代码

1
2
3
4
5
// 在已有日期显示代码后添加
if post.updated
.post-updated
i.fa.fa-history
span 最后更新:#{date(post.updated, 'YYYY-MM-DD')}

重新生成博客

1
hexo clean && hexo g && hexo s

主题配置示例

在 _config.anzhiyu.yml 中配置:

1
2
3
4
5
6
7
8
9
10
11
# 文章元信息
post_meta:
item_date: true
item_updated: true # 启用更新时间
item_category: true
item_tag: true
position: left

# 时间格式
date_format: 'YYYY-MM-DD'
updated_format: 'YYYY-MM-DD HH:mm'