Skip to content

Order feeds by the publication date, including one from the filename - #220

Open
pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/feed-order-by-publication-date
Open

pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/feed-order-by-publication-date

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

The RSS, Atom and JSON feed builders sort their items with

.sort_by { it.metadata.published_at || it.metadata.updated_at || Time.current }

metadata.published_at is the raw frontmatter value. The templates show resource.published_at instead (pubDate, <published>, date_published), and that one also picks up the date from a 2020-01-01-slug.md filename. So a post dated only by its filename has no frontmatter date and is sorted as if it was published now:

  • 2020-01-01-filename-dated.md (no published_at) is listed above frontmatter-dated.md with published_at: 2025-12-01, even though its pubDate says 2020.
  • With max_items, those old posts take the top slots and can push newer posts out of the feed.

The existing "sorted by date" tests pass only because the dummy posts are all filename-dated and loaded in filename order. Each Time.current is a little later than the last, so the reverse sort happens to come out right.

Fix

Sort by it.published_at, the same value the templates render, in all three builders. The updated_at and Time.current fallbacks are unchanged.

Tests

  • One test per feed (RSS, Atom, JSON) mixes a filename-dated post with a newer frontmatter-dated post and checks the order. All three fail without the change.
  • bin/rails test on Ruby 3.4: 432 runs, 1010 assertions, 0 failures. standardrb clean.

🤖 Generated with Claude Code

The RSS, Atom and JSON feeds sorted their items by
`metadata.published_at`, the raw frontmatter value, while the items show
`Resource#published_at`, which also takes the date from a
`YYYY-MM-DD-slug` filename. A post dated only by its filename had no
frontmatter date, so it was sorted as if published now: it went above
newer posts dated in the frontmatter, and with `max_items` could push them
out of the feed.

The feeds now sort by `Resource#published_at`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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