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

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 = "true" ++ to the .md files and {{ range $index, $page := first 50 (where .Site.Pages.ByPublishDate ".Params.displayHomepage" "true") }} 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

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 "Section" "!=" "blog-folder-2")).Pages }}