Derive slugs from title when provided#46
Open
tomershlasky wants to merge 1 commit into
Open
Conversation
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.
Summary
Auto-generated subdomains currently look like
warm-dawn-a1b2.easl.dev— purely random, even thoughPOST /publishalready accepts atitlefield. This PR uses that title (when present) to produce a self-describing slug likeq1-budget-report-a1b2, with the existing adjective-noun-hex format kept as the fallback.slugifyTitlehelper inpackages/worker/src/lib/slug.ts(NFKD normalize → strip combining marks → lowercase → non-alphanumeric runs →-→ trim → cap at 40 chars). Returnsnullwhen the result is empty or would collide with the reservedpreview-namespace.generateSlug(title?)accepts an optional title; falls back to the current adjective-noun-hex when no usable base is derived.generateUniqueSluginpublish.tsthreadsbody.titlethrough; the per-attempt random hex suffix continues to resolve same-title collisions inside the existing retry loop. Custom-slug path (body.slugvalidated viaisValidCustomSlug) is untouched.The 40-char cap +
-XXXXkeeps generated slugs ≤ 45 chars, well under the 48-char ceiling enforced bySLUG_REGEX. A new invariant test asserts every generated slug passesisValidCustomSlugacross 15 representative inputs.Examples (verified locally against
wrangler dev)Q1 Budget Reportq1-budget-report-cd51dawn-edge-03fa(fallback)Café Menucafe-menu-4545(NFKD strip)!!!/Preview releasepreview-guard)slug: "my-custom-name"my-custom-name(custom path unchanged)Note on title visibility
Titles will now appear in URLs. This is consistent with the "pages worth sharing" framing, but worth flagging — anyone publishing with sensitive titles can omit
titleto keep the current opaque slug, or pass an explicitslug.Test plan
pnpm test— 149/149 pass (3 new test groups inslug.test.ts: title derivation, preview-guard, broad invariant across 15 titles)pnpm typecheck— clean across worker, cli, mcppnpm test:e2e— 12/12 pass in the Cloudflare Workers runtime (custom-slug + untitled paths still work end-to-end)pnpm build— clean dry-run deploywrangler devfor all the cases in the table above