Skip to content

Conversation

@sam-shift72
Copy link
Contributor

@sam-shift72 sam-shift72 commented Dec 16, 2025

Improvements to support blog post pages.

  • Add post page type and support a published_date on pages.
  • PageIndex data source: configurable filter and sort to enable a blog posts in reverse chronological order paginated listing
  • Refactored pagination. Allow configuring a different path for the first page, e.g. /posts/ then /posts/2/, /posts/3/ etc. for subsequent pagination.
  • Page data source: warn instead of failing site build if the template doesn't support a particular page type

Extra Datasource Configuration

You can pass extra options through to the datasource in your Kibble.json, for example:

{
  "routes": [
    {
      "name": "postIndex",
      "datasource": "PageIndex",
      "urlPath": "/posts/:index/",
      "options": {
        "pageTypes": ["post"],
        "sortBy": ["published_date:desc", "title:asc"]
      },
      "pageSize": 10
    },
  ]
}

The PageIndex source supports filtering down to particular page types to include in the index listing, as well as sorting criteria.

Pagination

You can configure a different path for page 1 of paginated index by using firstPageUrlPath

{
  "routes": [
    {
      "name": "pageIndex",
      "datasource": "PageIndex",
      "firstPageUrlPath": "/pages/",
      "urlPath": "/pages/:index/",
      "pageSize": 10
    }
  ]
}

Internally, pagination has been refactored so that it's now a standalone concern that can easily be added to any data source that needs it by calling ctx.Paginate(len(items)) on the render context. This returns a list of pages that can be iterated over, and calculates the slice indexes for each page.

Caveats

Currently, configuring routes for different kinds of pages isn't supported.

I had initially added the pageTypes filter to the Page datasource, so that you could define different routes to render specific types of pages — blogs on /posts/, curated pages on /curated/ and everything on /pages/

{
  "routes": [
    {
      "name": "postItem",
      "datasource": "Page"
      "urlPath": "/posts/:slug",
      "options": {
        "pageTypes": ["post"]
      },
    },
    {
      "name": "curatedPageItem",
      "datasource": "Page"
      "urlPath": "/curated/:slug",
      "options": {
        "pageTypes": ["curated"]
      },
    },
    {
      "name": "pageItem",
      "datasource": "Page"
      "urlPath": "/page/:slug"
    },
  ]
}

While this generated the site correctly, it exposed an issue with the way Kibble's link generation works: the routeTo functions will just pick the first route whose datasource claims to handle a particular entity/slug. With the above config, every link would be generated as /posts/....

Supporting this will take a bit more refactoring, such as instantiating each datasource per-route so that methods like IsSlugMatch, GetRouteForSlug, and GetRouteForEntity can have access to the datasource options

e.g. /posts/ rather than /posts/1 for the index, then subsequent can be
/posts/2 etc.
the page data source supports a `:type` substitution, but currently it
dies if there's a page type the template doesn't support. Now it just
warns and keeps going. This should avoid failing site builds.
Refactored into a reusable method on the RenderContext to handle much of
the pagination and url generation logic.

This allows a lot of code in the datasource to be tidied up, and also
fixes some bugs like including the RoutePrefix on the pagination links
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants