Aggregating content from sections and creating separate pagination


#1

Let’s say I have three sections:

  1. News
  2. Stories
  3. Profiles

I want to aggregate this content into a geographic context that makes sense for my users (U.S. States) so I create a section for States, too. On each state page I show the five most recent pieces of content from each of the other sections with a shortcode:

Alabama page (/states/alabama.md)

Recent News

{{< section-content-by-tag tag=“Alabama” section=“news” >}}

Recent Articles

{{< section-content-by-tag tag=“Alabama” section=“articles” >}}

Species in Alabama

{{< section-content-by-tag tag=“Alabama” section=“wildlife” >}}

Question

Older content is pushed off of this page once five newer pieces have been written. I want to create an archive for that content.

How would I go about creating a page that paginates all articles tagged with Alabama (skipping, or after the five showed on the Alabama section page), a page that paginates all news tagged with Alabama, and a page with all profiles tagged with Alabama?

According to the docs only the homepage, section templates, and taxonomy templates support pagination. Is what I’m trying to accomplish even possible as of yet? Do I need to reorganize my content?

This comment from Bep may or may not be relevant here:

Remember that this is a static site generator, so all the paginator pages are static, so for the node pages (home page, taxonomy page) there is 0 or 1 paginator (not 2 or 3 … where should we put those pages?).

I can kinda get half way there through taxonomies by paginating all content tagged with Alabama and grouping by section, but the user would have to page through 10 pages before they hit profiles content.

taxonomy/tag.html

{{ $paginator := .Paginate .Data.Pages }}
{{ range  $paginator.Pages.GroupBy "Section" }}
  <h2>{{ title .Key }}</h2>
    {{ range .Pages }}
      {{ .Render "summary"}}
    {{ end }}
  {{ end }}
{{ partial "pagination.html" . }}

#2

I see several questions, but let me try to address the core question (related to the max 1 paginator rule).

To get pagination you need physical pages on disk, and this can be done with a “aggregate section” with no content files (or no regular content files) and with a list template that looks something like this:

{{ range .Paginate ( where .Site.RegularPages "Section" "in" slice("news", "stories", "profiles").Pages.GroupBy "Section" ) }}

You will of course have to adapt the query above (I’m not sure I typed it correctly), but I believe using the GroupBy should give you the “archive” pages you want.


#3

I think the solution you mention is more or less what I’ve achieved with the taxonomy solution at the end of my question. This works, but if I have many articles or news stories then the profile content is buried deeply on page 10+. Ideally I’d like to have separate pagination for each of those sections.

My content is structured like so:

/states
  alabama.md
  florida.md
  georgia.md
  ...

where each state page uses shortcodes to show the most recent 5 pieces of content from each of the mentioned sections. In addition to this I would like to have:

  • /alabama/articles paginate all articles starting with article #6
  • /alabama/news paginate all news starting with news #6
  • /alabama/profiles paginate all profiles starting with profile #6

If I understand you correctly I would need a physical page on disk for each of these paginators?

Thanks for your support!


#4

More like a physical Directory.

So there can be

/states/page/2

but not

/states/someotherpage/2

You can not put two paginators inside /state.