Back

总觉得 tags, categories 等页面可以合并成为一页。这样检索起来更方便一些。成果 https://www.ftls.xyz/retrieval/

初始配置

config.toml

# 用于分类的设置
[taxonomies]
author = "authors"
category = "categories"
tag = "tags"
series = "series"
retrieval = "retrieval"
toml

失败尝试

尝试使用 yaml 中的锚点和引用。

tags: &tag []
categories: &cat []
retrieval:
 tag: *tag
 cat: *cat
yaml

很遗憾,失败了。这在单页面上,也就是说具体页面。可以成功,然而在检索页却并不是可以成功的。 https://www.ftls.xyz/retrieval/ 不能获取到正确数据。

正确尝试

使用如下在 terms.html 中获取自定义分类的具体内容。

{{- $terms := $.Site.Taxonomies.series.ByCount -}}
text

这里使用的是 Doit 的主题。大家可以借鉴一下看看大致原理。知道有这个写法,大致就知道怎么写的了。

themes\DoIt\layouts\taxonomy\terms.html end 前新增的内容

加入之后的整体 terms.html ,也可以直接放到 layouts\taxonomy\terms.html 下,这个文件夹优先级比主题高。

优化

2024-04-21 优化,使用 Hugo 模板查找顺序。

content/retrieval.md

---
title: 检索
layout: retrieval
---
md

layouts/page/retrieval.html

assets/css/_custom.scss

Hugo themes Doit 合并 tags , categories 为检索页
https://www.ftls.xyz/posts/20221214-hugo%E5%90%88%E5%B9%B6%E6%A3%80%E7%B4%A2%E9%A1%B5/
Author 恐咖兵糖
Published at
Copyright CC BY-NC-SA 4.0