Skip to content

feat: generate URL-safe slugs from post titles using Enrichr#347

Draft
crisjonblvx wants to merge 1 commit intoshadcn-ui:mainfrom
crisjonblvx:feat/enrichr-slug-generation
Draft

feat: generate URL-safe slugs from post titles using Enrichr#347
crisjonblvx wants to merge 1 commit intoshadcn-ui:mainfrom
crisjonblvx:feat/enrichr-slug-generation

Conversation

@crisjonblvx
Copy link

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.tsgenerateSlug() helper (~35 lines, native fetch, no npm deps)
  • app/api/posts/route.ts — calls generateSlug(title) on post creation, includes slug in the response
  • .env.exampleENRICHR_API_KEY= placeholder

Why 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:

  • First 1,000 calls/month free
  • $0.00001/call after that (one-thousandth of a cent — generate 1M slugs for $10)
  • Zero new npm dependencies (uses native fetch)
  • Works in Edge Runtime, Node.js, and Deno
  • Graceful degradation — returns null (not an error) if ENRICHR_API_KEY is not set

Setup: Add ENRICHR_API_KEY to .env — get a free key at enrichrapi.dev

Example

// Before: manual, error-prone slug logic
const slug = title.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '')
// → "my-first-post--caf--more" ❌

// After: Enrichr handles Unicode, accents, and edge cases
const slug = await generateSlug(title)
// → "my-first-post-cafe-more" ✅

Changes

  • lib/enrichr.tsgenerateSlug(text, separator?) helper
  • app/api/posts/route.ts — generates slug on post creation, returns { id, slug }
  • .env.example — added ENRICHR_API_KEY= placeholder

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant