gpt4 book ai didi

go - Range 函数在我的模板中提供了额外的输出

转载 作者:数据小太阳 更新时间:2023-10-29 03:18:46 25 4
gpt4 key购买 nike

我正在关注 this链接以了解如何创建文件页面。我正在使用 hugo-xmin稍作修改的主题。

据我所知,range 会遍历页面并打印出来。但是,我还得到了一个额外的 0001。我不明白为什么。我仍然是 Hugo 和 Go 的初学者。

我的输出(红色圈出的部分不是我想要的)

enter image description here

我的archives.html

{{ partial "header.html" . }}

<div class="article-meta">
<h1><span class="title">{{ .Title | markdownify }}</span></h1>
{{ with .Params.author }}<h2 class="author">{{ . }}</h2>{{ end }}
{{ if (gt .Params.date 0) }}<h2 class="date">{{ .Date.Format "2006/01/02" }}</h2>{{ end }}
</div>



<main class="content" role="main">
<div class="inner">
{{ range (.Site.RegularPages.GroupByDate "2006") }}
<h3>{{ .Key }}</h3>
<ul>
{{ range (where .Pages "Type" "post") }}
<li>
<span class="date">{{ .Date.Format "2006/01/02" }}</span>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ end }}
</ul>
{{ end }}
</div>
</main>


{{ 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" . }}

<div class="article-meta">
<h1><span class="title">{{ .Title | markdownify }}</span></h1>
{{ with .Params.author }}<h2 class="author">{{ . }}</h2>{{ end }}
{{ if (gt .Params.date 0) }}<h2 class="date">{{ .Date.Format "2006/01/02" }}</h2>{{ end }}
</div>


{{ range (where .Site.RegularPages "Section" "!=" "").GroupByDate "2006" }}
<h2>{{ .Key }}</h2>
<ul>
{{ range .Pages }}
<li>
<span class="date">{{ .Date.Format "2006/02/02" }}</span>
<a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ end }}
</ul>
{{ end }}



{{ partial "footer.html" . }}

关于go - Range 函数在我的模板中提供了额外的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57138939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com