Hugo(静态网站生成器)特定URL的列表

huangapple go评论110阅读模式
英文:

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文件,每当我访问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

英文:

let's say I have the following structure

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

Then I also have the layouts/_default/list.html file which will be called every time I visit the URLs example.com/, example.com/blog-topic-1/, and example.com/blod-topic-2/

So the problem I have is that I don't want the layouts/_default/list.html file to generate the same content for these different paths..

I overcame the problem of only displaying certain articles in the homepage by adding ++ displayHomepage = &quot;true&quot; ++ to the .md files and {{ range $index, $page := first 50 (where .Site.Pages.ByPublishDate &quot;.Params.displayHomepage&quot; &quot;true&quot;) }} to the list.html file, but I can't figure out what to do if I don't want to display blog-article-2-1.md when visiting example.com/blog-folder-1/

Any help would be greatly appreciated <3

答案1

得分: 1

这里的文档有点难以排序。我将链接到Hugo文档的重要主题,以便您能够阅读更多详细信息。在查看了您的内容组织后,有两个部分

  • blog-folder-1
  • blog-folder-2

因此,在您的主题中,您可以为每个部分定义一个模板。如果没有提供模板,Hugo将使用默认模板。

因此,在您的布局文件夹中有以下逻辑:/layouts/SECTION/LAYOUT.html

对于您的情况,您可以定义一个默认布局。例如,如果blog-folder-2需要另一个模板,您的结构将如下所示:

layouts/
  ▾ _default/
      single.html
  ▾ blog-folder-2/
      single.html

如果您想在列表中过滤出一个部分,您需要使用页面变量

在遍历站点时,您可以添加一个where子句:

 {{ range $i, $p := (.Paginate (where .Data.Pages "Section" "!=" "blog-folder-2")).Pages }}
英文:

At this point the documentation is a little bit hard to order. I am going to link the important topics to the hugo documentation so that you are able to read more details. After looking to your Content Organisation there are two Sections:

  • blog-folder-1
  • blog-folder-2

So inside your theme you are able to define one template for each section. If there is no template provided hugo uses the default.

So inside your layouts folder there is that logic: /layouts/SECTION/LAYOUT.html

For your case you can define a default layout. When for example blog-folder-2 needs another template your structure would look like this:

layouts/
  ▾ _default/
      single.html
  ▾ blog-folder-2/
      single.html

If you want to filter out one section inside a list, you need to use the page variables.

At that points where you are ranging over the sites you can add a where clause:

 {{ range $i, $p := (.Paginate (where .Data.Pages &quot;Section&quot; &quot;!=&quot; &quot;blog-folder-2&quot;)).Pages }}

huangapple
  • 本文由 发表于 2017年2月21日 09:39:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/42357204.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定