文章页中对文章的分类标签说明

打开/themes/polk/layout/post.ejs,在

1
2
3
4
5
6
<% if (page.tags && page.tags.length){ %>
<%- list_tags(page.tags, {
show_count: false,
class: 'post-tag'
}) %>
<% } %>

后面添加上

1
2
3
4
5
<strong>分类:
<% if(page.categories && page.categories.length){ %>
<%- list_categories(page.categories, {show_count: false,class: 'post-tag'}) %>
<% } %>
</strong>

菜单导航过去的分类标签页面渲染

/themes/polk/layout模仿post.ejs的内容新建tags.ejs和categories.ejs两个文件

tags.ejs

1
2
3
4
5
6
7
8
9
10
11
12
<%- partial('_partial/header') %>
<article class="post">

<% if (site.tags && site.tags.length){ %>
<%- list_tags(site.tags, {
show_count: false,
class: 'post-tag'
}) %>
<% } %>

</article>
<%- partial('_partial/footer') %>

categories.ejs

1
2
3
4
5
6
7
8
9
<%- partial('_partial/header') %>
<article class="post">

<% if(site.categories && site.categories.length){ %>
<%- list_categories(site.categories, {show_count: false,class: 'post-tag'}) %>
<% } %>

</article>
<%- partial('_partial/footer') %>

/source/tags/index.md文件的元数据区添加layout: "tags"

/source/categories/index.md文件的元数据区添加layout: "categories"

一件不清楚其价值的事情

我不太懂这样做的原理和好处,猜测是让hexo在元数据区时对照好变量的值,比如tags对照“tags”后面的字符串。。。

打开/scaffolds/post.md,修改其内容为

1
2
3
4
5
6
---
title: {{ title }}
date: {{ date }}
tags: {{ tags }}
categories: {{ categories }}
---

博文中tags和categories的写法见/2023/01/20/hexo-create-tags-categories-rss/

参考链接:hexo categories和tags页面不显示解决办法

hexo(sakura)——标签、分类页面美化

list_categories

创建于2023.2.8/22.17,修改于2023.2.8/22.17