Collapse _build_posts double sort into one comparator (#50)#68
Merged
Conversation
_build_posts pre-sorted source files by basename and then re-sorted the constructed posts by date, relying on sort stability to keep the basename order as a tiebreak. Replace the two passes with a single sort whose comparator is date-descending, basename-ascending -- the same rule _ordered_basenames uses on the incremental path, so full and incremental publishes now agree on ordering. The grep still accepts .md and .markdown. Output order is unchanged; adds t/post_sort.t to lock the contract, including the mixed-extension, same-date tiebreak case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CI caught that the previous commit broke t/basic.t on Linux: removing the basename sort that ran *before* the map meant posts were constructed in readdir order. Construction has side effects (it can die on a malformed file, rewrites source files, resolves tag-case conflicts first-seen-wins), so a non-deterministic order made publish_all report no-title.md's error before bad-date.md's on ext4, failing the "not in W3C format" assertion. Restore the basename pre-sort so construction is deterministic, keeping the explicit date-then-basename comparator on the built posts. The pre-sort orders file objects (not posts), so it's cheap -- it isn't redundant, it's load-bearing for determinism. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #50.
Diagnosis
_build_postsdid two sorts:The inner basename sort isn't thrown away (it's the tiebreak for posts that share a date, preserved through the stable outer sort), but doing it as a separate pass is redundant work, as noted on the issue.
Fix
Collapse to a single sort with an explicit comparator — date descending, basename ascending:
This is the same comparator
_ordered_basenamesalready uses on the incremental publish path, so a full publish and an incremental publish now provably agree on ordering. Thegrepstill accepts both.mdand.markdown.Behavior
Output order is unchanged (the old stable-sort + pre-sort produced the same result); this drops the redundant pass and makes the tiebreak explicit.
t/post_sort.tpins the contract — newest-first with a basename tiebreak — and was written against the old code first to confirm the order doesn't change, including the mixed.md/.markdown, same-date case. Full suite green.🤖 Generated with Claude Code