Give emoji-only post titles distinct filenames (#52)#69
Merged
Conversation
A post whose title is made entirely of characters that can't appear in a filename (e.g. emoji) slugged down to an empty string, so every such post on a given day produced the same "YYYY-MM-DD-.html" and silently overwrote its predecessor. When the title slug comes out empty, fall back to a short hash of the title. Distinct titles now get distinct, deterministic, stable filenames. md5_hex/encode_utf8 come from core Digest::MD5 (already a Plerd dependency) and Encode. Adds t/emoji_title.t covering two emoji-only titles on the same day. 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 #52.
Diagnosis
Plerd::Post::_build_published_filenamebuilds a slug from the title by stripping HTML, turning whitespace into hyphens, and then deleting everything that isn't\wor-:A title made entirely of emoji (or any non-word characters) is reduced to the empty string, so the filename becomes
YYYY-MM-DD-.html. Two such posts on the same day — e.g.😀and🎩🎩— both resolve to2021-01-19-.html, and one silently overwrites the other on disk.Fix
When the slug comes out empty, fall back to a short hash of the title:
Distinct titles now get distinct, deterministic filenames (
2021-01-19-2a02eac39d.html,2021-01-19-0c35dfec4f.html), and the value is stable across republishes because it's written back into the source'spublished_filenamemetadata on first publish.md5_hex/encode_utf8come from coreDigest::MD5(already a Plerd dependency) andEncode— no new deps. (Two posts sharing an identical title on the same day still collide, but that's the pre-existing, separate collision class that affects ordinary titles too.)Test
Adds
t/emoji_title.t: publishes two emoji-only titles on the same day and asserts the two published filenames are distinct, non-empty, and that both HTML files actually exist on disk. Failed before the fix, passes now. Full suite green (83 tests).🤖 Generated with Claude Code