TableauPaginationExtension - Paginated Indexes for Tableau

Over the last several months, I’ve been using Tableau to rebuild my long-neglected website. Tableau is part of the Elixir Tools project headed by @mhanberg, and is built on top of MDEx by @leandrocp. This library is one of ten libraries and Elixir extensions that I built. Most of these were built with the assistance of Kiro.

TableauPaginationExtension is an extension for Tableau that helps with the creation of paginated indexes for collections of posts, tags, or other data.

A configuration like

config :tableau, TableauPaginationExtension,
  enabled: true,
  collections: [
    posts: [
      permalink: "/posts/:page?",
      layout: MySite.RootLayout,
      template: MySite.PostsPage,
      per_page: 5
    ]
  ]

will generate paginated posts like this:

/posts      → Page 1 (5 posts)
/posts/2    → Page 2 (5 posts)
/posts/3    → Page 3 (5 posts)

Map-like collections (such as tags) can be paginated both on keys (tag names) and on key/value pairs (paginated pages within a tag).

Simple Lists

Paginate simple lists like posts or pages:

posts: [
  permalink: "/posts/:page?",
  layout: MySite.RootLayout,
  template: MySite.PostsPage,
  per_page: 10
]

Tag Index

Paginate list of all tags (map keys):

tag_index: [
  key_path: [:tags],
  permalink: "/tags/:page?",
  layout: MySite.RootLayout,
  template: MySite.TagIndexPage,
  per_page: 50
]

Tag Pages

Paginate posts within each tag (values):

tag_pages: [
  key_path: [:tags],
  permalink: "/tags/:tag/:page?",
  layout: MySite.RootLayout,
  template: MySite.TagPage,
  per_page: 20
]

Permalink Patterns

Collection permalink strings have to end with /:page or /:page?, where /:page? omits the first page number, so that /prefix/:page? becomes /prefix, /prefix/2, etc. instead of /prefix/1, /prefix/2, etc.

Template Variables

When rendering the index page templates, the following are made available as assigns:

  • @posts: Items for current page
  • @page_number: Current page (1-indexed)
  • @total_pages: Total number of pages
  • @prev_page_url / @next_page_url: Navigation URLs
  • @first_page_url / @last_page_url: Jump to endpoints

3 Likes