Hexo笔记6-Hexo博客的type字段
在使用 Hexo 搭建博客时,除了常规的文章(post),我们还常常需要创建各种独立页面,例如“关于我”、“归档”、“标签”、“分类”等。这些页面背后都有一个核心概念 —— type
。本篇文章将全面梳理 Hexo 页面中 type
的作用与常见类型,帮助你更好地定制属于自己的博客结构。
🧠 什么是 type
?
在 Hexo 中,每个页面(Page)都会有一个 type
属性,用于告诉 Hexo 或主题如何渲染这个页面。它相当于是页面的“身份标签”。
如果不指定 type
,Hexo 默认使用 page
或 post
类型进行处理。
📦 常见的 type
类型
type 值 |
用途说明 | 是否自动识别 | 常见路径 |
---|---|---|---|
posts |
默认值,表示这是文章(Post) | ✅ 是 | source/_posts/*.md |
page |
普通独立页面,如 about、links 等 | ✅ 是 | source/about/index.md 等 |
tags |
标签页面,展示所有标签和相关文章 | ❌ 否 | source/tags/index.md |
categories |
分类页面,展示所有分类和相关文章 | ❌ 否 | source/categories/index.md |
archive |
一些主题中用于归档页 | ❌ 否 | /archives/ |
links |
友链页面,依赖主题支持 | ❌ 否 | source/links/index.md |
message |
留言板页面,依赖主题支持 | ❌ 否 | source/message/index.md |
custom |
你自定义的任何页面(如 gallary) | ❌ 否 | 需配合主题中的模板渲染 |
✍️ 创建一个带 type
的页面示例
以创建标签页为例:
1 | hexo new page tags |
然后编辑 source/tags/index.md
,加入以下内容:
1 | --- |
🔍 如何查看主题支持的 type
?
你可以查看 themes/xxx/layout/
文件夹:
tags.pug
→ 支持type: tags
categories.pug
→ 支持type: categories
links.pug
→ 支持type: links
message.pug
→ 支持type: message
archive.pug
→ 支持type: archive
当然,你也可以创建 _custom/xxx.pug
来扩展自定义类型。
评论