feat: generate URL-safe slugs from post titles using Enrichr#347
Draft
crisjonblvx wants to merge 1 commit intoshadcn-ui:mainfrom
Draft
feat: generate URL-safe slugs from post titles using Enrichr#347crisjonblvx wants to merge 1 commit intoshadcn-ui:mainfrom
crisjonblvx wants to merge 1 commit intoshadcn-ui:mainfrom
Conversation
Adds lib/enrichr.ts — a zero-dependency wrapper around the Enrichr API that generates URL-safe slugs from post titles (Unicode-aware, handles accents, emoji, and special characters). Slug is generated from the post title on creation and included in the API response, making it easy to build human-readable post URLs without manual sanitization. Gracefully degrades: if ENRICHR_API_KEY is not set, slug is null and everything continues to work as before. Setup: add ENRICHR_API_KEY to .env — free key at https://enrichrapi.dev (1,000 calls/month free, $0.00001/call after that)
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
Adds
lib/enrichr.ts— a zero-dependency wrapper around Enrichr that generates URL-safe slugs from post titles on creation.What this adds:
lib/enrichr.ts—generateSlug()helper (~35 lines, native fetch, no npm deps)app/api/posts/route.ts— callsgenerateSlug(title)on post creation, includesslugin the response.env.example—ENRICHR_API_KEY=placeholderWhy this is useful:
Post titles like
"My First Post — Café & More!"produce"my-first-post-cafe-more"automatically — Unicode-aware, handles accents, diacritics, and special characters correctly.Why Enrichr:
fetch)null(not an error) ifENRICHR_API_KEYis not setSetup: Add
ENRICHR_API_KEYto.env— get a free key at enrichrapi.devExample
Changes
lib/enrichr.ts—generateSlug(text, separator?)helperapp/api/posts/route.ts— generates slug on post creation, returns{ id, slug }.env.example— addedENRICHR_API_KEY=placeholder