特定 URL 的 Hugo(go 静态站点生成器)列表
Hugo (go static site generator) list for specific URLs
假设我有以下结构
content
- blog-folder-1
-- blog-article-1-1.md
-- blog-article-1-2.md
- blog-folder-2
-- blog-article-2-1.md
-- blog-article-2-2.md
然后我还有 layouts/_default/list.html
文件,每次访问 URL example.com/
、example.com/blog-topic-1/
和 example.com/blod-topic-2/
时都会调用该文件
所以我遇到的问题是我不希望 layouts/_default/list.html
文件为这些不同的路径生成相同的内容..
我通过在 .md 文件中添加 ++ displayHomepage = "true" ++
和在 list.html
文件中添加 {{ range $index, $page := first 50 (where .Site.Pages.ByPublishDate ".Params.displayHomepage" "true") }}
来解决主页中仅显示某些文章的问题,但我无法理解如果我不想在访问 example.com/blog-folder-1/
时显示 blog-article-2-1.md
该怎么办
任何帮助将不胜感激 <3
此时文档有点难以订购。我将 link hugo 文档的重要主题,以便您能够阅读更多详细信息。查看您的 Content Organisation there are two Sections 后:
- blog-folder-1
- blog-folder-2
因此在您的主题中您可以 define one template for each section。如果没有提供模板,hugo 使用默认模板。
所以在您的布局文件夹中有这样的逻辑:/layouts/SECTION/LAYOUT.html
对于您的情况,您可以定义默认布局。例如,当 blog-folder-2 需要另一个模板时,您的结构将如下所示:
layouts/
▾ _default/
single.html
▾ blog-folder-2/
single.html
如果你想过滤掉列表中的一个部分,你需要使用page variables。
在您遍历网站的那一点上,您可以添加一个 where 子句:
{{ range $i, $p := (.Paginate (where .Data.Pages "Section" "!=" "blog-folder-2")).Pages }}
假设我有以下结构
content
- blog-folder-1
-- blog-article-1-1.md
-- blog-article-1-2.md
- blog-folder-2
-- blog-article-2-1.md
-- blog-article-2-2.md
然后我还有 layouts/_default/list.html
文件,每次访问 URL example.com/
、example.com/blog-topic-1/
和 example.com/blod-topic-2/
所以我遇到的问题是我不希望 layouts/_default/list.html
文件为这些不同的路径生成相同的内容..
我通过在 .md 文件中添加 ++ displayHomepage = "true" ++
和在 list.html
文件中添加 {{ range $index, $page := first 50 (where .Site.Pages.ByPublishDate ".Params.displayHomepage" "true") }}
来解决主页中仅显示某些文章的问题,但我无法理解如果我不想在访问 example.com/blog-folder-1/
blog-article-2-1.md
该怎么办
任何帮助将不胜感激 <3
此时文档有点难以订购。我将 link hugo 文档的重要主题,以便您能够阅读更多详细信息。查看您的 Content Organisation there are two Sections 后:
- blog-folder-1
- blog-folder-2
因此在您的主题中您可以 define one template for each section。如果没有提供模板,hugo 使用默认模板。
所以在您的布局文件夹中有这样的逻辑:/layouts/SECTION/LAYOUT.html
对于您的情况,您可以定义默认布局。例如,当 blog-folder-2 需要另一个模板时,您的结构将如下所示:
layouts/
▾ _default/
single.html
▾ blog-folder-2/
single.html
如果你想过滤掉列表中的一个部分,你需要使用page variables。
在您遍历网站的那一点上,您可以添加一个 where 子句:
{{ range $i, $p := (.Paginate (where .Data.Pages "Section" "!=" "blog-folder-2")).Pages }}