@20minutes/content-slug
v2.0.1
Published
Content slugification for 20 Minutes
Downloads
726
Readme
@20minutes/content-slug
URL slugification used by 20 Minutes for content URL.
Compatibility
- Requires Node.js >= 22.
Installation
yarn add @20minutes/content-slugUsage
import { toContentSlug, unaccentize} from '@20minutes/content-slug'
toContentSlug('j'ai mangé des pommes et des poires et c'était bon !')
// mange-pommes-poires-bon
unaccentize('mangé')
// mangeSlug Rules
toContentSlug applies the following transformations:
- lowercases the input
- replaces underscores with spaces before normalization
- removes diacritics such as
é,Å, orç - removes a built-in list of common French stop words
- collapses punctuation and whitespace through
url-slug - keeps only the slug-safe output produced by
url-slug - truncates the final slug to 150 characters
- removes trailing hyphens after truncation
Examples:
toContentSlug("le et de ou à")
// ""
toContentSlug("Bonjour!!!___test??")
// "bonjour-test"
toContentSlug("À l'école des Ångströms")
// "ecole-angstroms"
toContentSlug("🍕 Café 東京")
// "cafe"unaccentize only removes diacritics. It does not slugify, trim, or remove punctuation.
