Add Slugify to turn text into a lowercase hyphenated slug #10

Merged
sneak merged 1 commits from clawbot/util:proposal-slugify into master 2026-09-05 05:44:52 +02:00
Contributor

Adds Slugify(input string) string, which turns a piece of text into lowercase
ASCII letters, digits and single hyphens: safe for a URL path, a filename or a
fragment identifier.

This belongs here because anything that publishes a page, writes a file named
after a title or builds an anchor needs it, and it pairs with the existing
FilterToAlnum, which removes separators entirely instead of keeping them as
word boundaries.

Things to know:

  • Characters outside ASCII are treated as separators, not folded to a nearest
    ASCII relative, so "Grüße" becomes "gr-e" and a string of only non-ASCII text
    becomes empty. Folding properly needs Unicode tables from
    golang.org/x/text, and this package should not take on a dependency for it.
    The doc comment says so plainly, and there is a test for both cases.
  • A trailing separator produces no trailing hyphen: the hyphen is only written
    once another usable character turns up.
  • Two different titles can slugify to the same string, so callers that need
    uniqueness still have to handle collisions themselves.
  • The code is in a new file, slugify.go, so that the ten proposal branches do
    not all conflict in the same place.
  • make test on this branch reports one failure, TestNowUnixMicro. That test
    already fails on master and is unrelated to this change.

Model: opus-5

Adds `Slugify(input string) string`, which turns a piece of text into lowercase ASCII letters, digits and single hyphens: safe for a URL path, a filename or a fragment identifier. This belongs here because anything that publishes a page, writes a file named after a title or builds an anchor needs it, and it pairs with the existing `FilterToAlnum`, which removes separators entirely instead of keeping them as word boundaries. Things to know: - Characters outside ASCII are treated as separators, not folded to a nearest ASCII relative, so "Grüße" becomes "gr-e" and a string of only non-ASCII text becomes empty. Folding properly needs Unicode tables from `golang.org/x/text`, and this package should not take on a dependency for it. The doc comment says so plainly, and there is a test for both cases. - A trailing separator produces no trailing hyphen: the hyphen is only written once another usable character turns up. - Two different titles can slugify to the same string, so callers that need uniqueness still have to handle collisions themselves. - The code is in a new file, `slugify.go`, so that the ten proposal branches do not all conflict in the same place. - `make test` on this branch reports one failure, `TestNowUnixMicro`. That test already fails on `master` and is unrelated to this change. Model: opus-5
clawbot self-assigned this 2026-09-05 05:27:05 +02:00
clawbot added 1 commit 2026-09-05 05:27:06 +02:00
Slugify lowercases text and keeps only ASCII letters and digits, turning every
run of other characters into a single hyphen with none left at either end.
Comes with a doc comment and table-driven tests. (closes #9)

Model: opus-5
sneak merged commit 74b448851e into master 2026-09-05 05:44:52 +02:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/util#10