You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hugo分页未应用自定义筛选:无法仅展示code类型页面

Hugo 分页筛选 Type/Section 无效问题

我在首页使用 Paginate 生成项目列表,希望仅展示 type 为 "code" 的页面,但筛选完全无效,页面显示了所有类型的内容(如 Calendar、About 这类不属于 code 的页面也出现在列表中)。

原始代码

{{ $paginator := .Paginate (where .Site.Pages "Type" "code") }}
{{ range $paginator.Pages }}
{{ partial "list.html" . }}
{{ end }}
{{ partial "paginator.html" . }}

这段代码意图筛选出 type 为 "code" 的页面数组,传入 Hugo 的 Paginate 方法后遍历分页内容,但无法过滤掉 /code/ 文件夹以外的内容。

已尝试的解决方法

  • 在 {{ range $paginator.Pages }} 中添加筛选逻辑:虽能过滤内容,但会破坏分页功能(分页计数与实际展示的内容数量不符)
  • 改用 (where .Site.RegularPages "Type" "code") 等不同筛选写法,均无效果
  • 排查是否存在多次使用 Paginate 的情况:检查所有文件及主题文件后,确认仅当前实例使用了 Paginate

后续尝试(编辑补充)

将代码中的 "Type" 替换为 "Section",代码如下,但问题仍未解决:

{{ $paginator := .Paginate (where .Site.Pages "Section" "code") }}
{{ range $paginator.Pages }}
{{ partial "list.html" . }}
{{ end }}
{{ partial "paginator.html" . }}

内容的提问来源于stack exchange,提问作者Ben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 20:35:23