Skip to content

feat(blog): add first/after template functions and listPages config - #97

Merged
corylanou merged 2 commits into
mainfrom
feat/blog-list-page
Mar 15, 2026
Merged

feat(blog): add first/after template functions and listPages config#97
corylanou merged 2 commits into
mainfrom
feat/blog-list-page

Conversation

@corylanou

Copy link
Copy Markdown
Member

Summary

Adds generic template infrastructure inspired by Hugo's template functions:

  • first N .Items — returns the first N items from any slice (bounds-safe)
  • after N .Items — returns items after the Nth item from any slice (bounds-safe)
  • listPages config option — render the list template at additional paths beyond /, each with a .PagePath field so templates can conditionally show different content

These are generic features with no site-specific logic. Templates decide what to render.

Example usage in templates

{{/* Homepage: show latest 3 articles */}}
{{range first 3 .Articles}}...{{end}}

{{/* Check which list page we're on */}}
{{if eq .PagePath "/"}}...{{else}}...{{end}}

Example config

listPages:
  - blog
  - archive

This renders the list template at /blog/index.html and /archive/index.html in addition to /index.html.

Test plan

  • go test ./blog/... passes
  • first 3 .Articles returns at most 3 items, handles fewer gracefully
  • after 2 .Articles skips the first 2 items
  • listPages: [blog] generates /blog/index.html with .PagePath set to /blog/
  • Homepage .PagePath is /

Add generic template functions inspired by Hugo:
- first N items: returns the first N items from a slice
- after N items: returns items after the Nth item

Add listPages config option to render the list template at additional
paths beyond /. Each path receives a PagePath field so templates can
conditionally render different content per page.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c73c4e5e66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread blog/templates.go Outdated
@corylanou
corylanou merged commit cab53a6 into main Mar 15, 2026
3 checks passed
@corylanou
corylanou deleted the feat/blog-list-page branch March 15, 2026 17:46
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.

1 participant