Range 函数增加了附加输出到我的模板
来源:stackoverflow
2024-03-06 08:06:26
0浏览
收藏
IT行业相对于一般传统行业,发展更新速度更快,一旦停止了学习,很快就会被行业所淘汰。所以我们需要踏踏实实的不断学习,精进自己的技术,尤其是初学者。今天golang学习网给大家整理了《Range 函数增加了附加输出到我的模板》,聊聊,我们一起来看看吧!
问题内容
我正在点击此链接来了解如何创建档案页面。我使用的hugo-xmin 主题稍作修改。
据我了解,range
会浏览页面并应该将其打印出来。但是,我还得到了一个额外的 0001
。我不明白为什么。我还是 hugo 和 go 的初学者。
我的输出(红色圆圈部分不是我想要的)
我的archives.html
{{ partial "header.html" . }}
{{ .title | markdownify }}
{{ with .params.author }}{{ . }}
{{ end }}
{{ if (gt .params.date 0) }}{{ .date.format "2006/01/02" }}
{{ end }}
{{ range (.site.regularpages.groupbydate "2006") }}
{{ .key }}
{{ range (where .pages "type" "post") }}
-
{{ .date.format "2006/01/02" }}
{{ .title }}
{{ end }}
{{ end }}
{{ partial "footer.html" . }}
我的archives.md
---
title: "archives"
layout: "archives"
draft: false
---
this is archives
我的目录结构
.
├── archetypes
│ └── default.md
├── config.toml
├── content
│ ├── about.md
│ ├── archives.md
│ ├── _index.md
│ ├── post
│ │ ├── first_post.md
│ │ ├── sample_code.md
│ │ └── test_math.md
│ └── reading.md
├── data
├── layouts
├── static
└── themes
└── mytheme
├── archetypes
│ └── default.md
├── layouts
│ ├── 404.html
│ ├── archives.html
│ ├── _default
│ │ ├── archives.html
│ │ ├── list.html
│ │ ├── single.html
│ │ └── terms.html
│ ├── index.html
│ └── partials
│ ├── foot_custom.html
│ ├── footer.html
│ ├── head_custom.html
│ └── header.html
├── LICENSE.md
├── static
│ ├── css
│ │ ├── fonts.css
│ │ └── style.css
│ └── js
└── theme.toml
15 directories, 25 files
解决方案
在 hugo-lithium 的帮助下,我将 archives.html
更改为以下内容。它现在适用于我的用例。但我仍然不明白为什么0001首先出现。所以我现在不会将我的答案标记为正确。
{{ partial "header.html" . }}
{{ .Title | markdownify }}
{{ with .Params.author }}{{ . }}
{{ end }}
{{ if (gt .Params.date 0) }}{{ .Date.Format "2006/01/02" }}
{{ end }}
{{ range (where .Site.RegularPages "Section" "!=" "").GroupByDate "2006" }}
{{ .Key }}
{{ range .Pages }}
-
{{ .Date.Format "2006/02/02" }}
{{ .Title }}
{{ end }}
{{ end }}
{{ partial "footer.html" . }}
今天关于《Range 函数增加了附加输出到我的模板》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
- 下一篇
- 用http包装函数作为依赖项进行单元测试