chipsenkbeil / grid-side

Personal portfolio and blog for use by the Hugo generator.
MIT License
32 stars 21 forks source link

Cannot create a new custom post section #26

Closed cale-inspired closed 8 years ago

cale-inspired commented 8 years ago

Hey there, first of all: I am still very new to Hugo, so excuse me if the answer to my question should be obvious...

What I am trying to do: I would like to have several blog sections, sorted by content category (e.g. health, games, cars). All of those sections should have the same layout but (of course) different articles. The structure is supposed to be: site.com/health/health-post1/ site.com/games/games-post1/ etc. If this is achieved, I would like to go a step further and have site.com/all/ as well, where all posts of the listed sections will be shown. (Is this possible?)

What I have tried so far:

  1. Create folder "health" in /content/ and add articles.
  2. Add folder "health" to /layouts/ and put single.html in there with partial post/single.html.
  3. Add health.html to /layouts/section/ with partial post/list.html. => Result: I can access site.com/health/, however, it shows the same content as site.com/post/. As far as I understood your exampleSite, you did the same: You have created a custom post section which shows the same content as the post section.

My question: How can I do the same I have achieved so far, but with unique content for each section?

I have read the hugo docs on sections but they didn't help me... Maybe I still get something completely wrong about how sections work.

THX!

chipsenkbeil commented 8 years ago

With regard to the sections, the only functionality that the theme provides is providing a different name to the post section, not creating subsections the way you are trying to do. If you want sections, you can follow the docs here to create something like http://example.com/post/health/health-post1. I can't remember if Hugo provides indexing for sections or not when visiting a url like http://example.com/post/health.

If you want to provide sections using the partials that restrict posts to categories like health vs. games, Hugo might have some filtering capability. Alternatively, you could extend https://github.com/chipsenkbeil/grid-side/blob/master/layouts/partials/post/list.html#L29 to support filtering the pages that are listed.

cale-inspired commented 8 years ago

With regard to the sections, the only functionality that the theme provides is providing a different name to the post section, not creating subsections the way you are trying to do.

So is this a matter of the theme or Hugo itself? If it's just about the theme, then there should be a way to include that functionality manually, right? I definitely need indexing for the sections.

chipsenkbeil commented 8 years ago

Well, you can take a look at my site here. It's for https://chipsenkbeil.com (not senkbeil.org) and uses the post layout for multiple sections (note and post). Those are separate sections that can be accessed via https://chipsenkbeil.com/post/ and https://chipsenkbeil.com/note/. I don't have a section dedicated to retrieving all content, though. That would be layouts and content you would probably need to add on top of the theme.

cale-inspired commented 8 years ago

Perfect, thank you! That's exactly what I want to do. I will look into it and try to implement it in my site. BTW: I asked on the gohugo forums for the latter issue, and just got a reply that it was possible to list all articles with .Site.Pages. (see https://discuss.gohugo.io/t/list-page-for-all-content-of-all-sections/3832/2?u=inspiritana) Right now I am still tweaking the homepage design, afterwards I'll try to achieve that section stuff (and will post in here if/how I managed to do it). Cheers!

cale-inspired commented 8 years ago

Wow, it was in fact much easier than I thought:

  1. create section "all"
  2. use single.html layout from post/
  3. use list.html layout from post/ and modify the following: {{ range .Paginator.Pages }} to {{ range .Site.Pages }}

Edit: In order to display only blog sections, I use: {{ range where .Site.Pages "Section" != "not_wanted_section" }} OR: `{{ range .Site.Pages.ByPublishDate.Reverse }} {{ if or (eq .Section "wanted_section1") (eq .Section "wanted_section2")}}

  • {{.Title}}
  • {{end}}

    {{ end }}`

    That's it! Thanks for your help, Chip!

    chipsenkbeil commented 8 years ago

    Great! I'll close this issue. If you still need to discuss something regarding this, feel free to open it back up. If there is some code that needs to be amended, you are more than welcome to create another PR.