Different summary pages

Hmm, at the risk of outing myself as a complete hugo-noob:

I understand that for a section I can have a list page: _index.md

I understand how to theme/template this.

But I want to be able to offer multiple lists for a section, e.g.:

  • one ByDate
  • one ByWeight if weight is set (know how to do this … ha! :wink: )

This for multiple sections.

I know I can set layout in front-matter, tried, works. So best I can come up with, now, is:

create a section directory, add an _index.md switch layout to e.g. “posts-by-weight.html” and in this layout use .Site.Pages to iterate and filter this properly by Directory etc. pp.

this would result in about half a dozen “stub/dummy”-sections. Ok the same could be achieved with individually layout’d single pages, sure. This would spare me the subdirectories.

Nevertheless, this approach is somewhat tedious. I can avoid a bit of C&P with a partial then, but that’s it.

My question:

is there any best-practise or in other words more common and economic way to do this? Offering a section’s list in multiple sort-orders and filters? Can layouts be parameterised in a way?

Thx in advance!

Possibly you’ve already tried this, but if not:

Check if weight param is set. If it is, range by weight. If not, range by date. Then stick it in a partial like you mentioned.

You are right, I considered this. Thing is, that I want the user to be able to choose:
The site has two content-types: articles and posts. The usual stuff. And the homepage contains 4 “hit-lists, aka top 10s”:

  • features posts
  • recent posts
  • featured articles
  • recently changed articles

Each of the top-10-blocks has a “More…” link which shall point to a page holding ALL related content in the respective sort-order, paginated.

For the posts, I might take your proposal and call it a solution, but for the articles, this fails: featured articles are below a certain weight, but all articles have a weight (in a way), because this defines the order they appear in the menu(es). (Well this part is still under construction, I will likely fall back to taxonomy for the menus.)

I asked in the hope that someone jumps up and says sth like: c’mon, everybody does this in this easy way. But apparantly it is a matter to really design and work on the solution.

I’ll wait a bit more and then I’ll just experiment my way through it. Thanks anyway.

If I’m understanding you right, users could set a front matter param, something like orderByWeight. Depending if true/false, then you could work with this param in your templates.

Only after reading again, I understood your hint. I will have to think about the frontmatter param to select the sorting and filtering. I just wonder if this would get more complex than four layouts. I’d have to play with collection-variables and custom-params, did not do before. I will follow the idea for a while. Gets me to the next level, mabe :wink: learning … always learning.

Hey, thanks! Your hints brought me to the finish line.

I have now four content pages in the summaries section: featured-articles.md, recent-articles.md and featured-posts.md and recent-posts.md, respectively.

Their frontmatter sets three mentionable values: the layout setting to “summaries” and controlling the layout with the custom settings “sorting” and “dir”

Exemplarily the frontmatter looks like this:

title: "Dudel"
date: 2018-12-31T03:21:41+01:00
draft: false
weight: 2

The layout (_default/summaries.html) handles this like this:

{{ define "main" }}

{{ $collection := where .Site.Pages "Dir" (.Param "dir")}}
{{ $notfeatured := true }}
{{ if eq (.Param "sorting") "featured" }}
  {{ $collection = $collection.ByWeight }}
  {{ $notfeatured = false }}
{{ end }}
{{ if eq (.Param "sorting") "recent" }}
  {{ $collection = $collection.ByDate.Reverse }}
{{ end }}

<section id="main">
    Sorting is {{ .Param "sorting" }}<br/>
    Dir is {{ .Param "dir" }} <br/><br/>
      {{ range first 20 $collection }}
        {{ if .IsPage }}
          {{ if (or $notfeatured (ne .Weight 0)) }}
            <li>{{ .Title }} - {{ .Weight }} - {{ .Date }}</li>
      {{ end }}{{ end }}{{ end }}
{{ end }}

Basically the summaries pages rely on the summaries layout and get configured via sorting and dir params. I will now play with this to get it more compact. But in general it will do the job. Tests confirmed that.

Thanks a lot for hints.

Adrian, the koffeiniker