{
  "id": 19899549,
  "title": "Slug Generator: Cleaning Apostrophes, Ampersands and Trailing Hyphens Out of My Blog URLs",
  "url": "https://urgent.news/2026/11/14/slug-generator-cleaning-apostrophes-ampersands-and-trailing-hyphens",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-14T01:46:20.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/meng_meng_56f17e28e55f140/slug-generator-cleaning-apostrophes-ampersands-and-trailing-hyphens-out-of-my-blog-urls-21kl"
  },
  "original_language": "en",
  "account": "Moving 312 blog posts from an old WordPress site to Eleventy required cleaning up URLs that contained apostrophes, ampersands, trailing hyphens, and other characters. Last month, the CMS export provided titles exactly as they were typed by editors, which sometimes contained special characters such as —, & and !. To address these issues, the author experimented with three different methods to generate clean slugs for the blog posts.\n\nMethod 1: Python used the python-slugify library (version 8.0.0) to generate slugs by normalizing the text using NFKD encoding, removing non-ASCII characters, and replacing unwanted characters with hyphens. This approach handled collisions by appending the post ID to the slug. The resulting slugs were clean, with no curly apostrophes, em dashes, or other special characters. The author discovered that stripping trailing hyphens and using the lower() method contributed to generating a robust set of slugs.\n\nMethod 2: Node.js implemented the slugify package (version 1.6.6) to generate slugs from the exported CSV file. The strict flag was enabled to prevent the inclusion of percent-encoded characters like %, &, and @ in the final URLs. This method yielded identical slugs to the Python approach, confirming the reliability of the chosen slugification method.\n\nMethod 3: For quick fixes in the browser, the author utilized an online slug generator to generate URLs for one-off titles. This method flagged issues such as double hyphens and allowed for manual adjustments before publishing. However, the author highlighted three potential pitfalls: handling duplicate apostrophes, trailing hyphens, and ensuring that slugs did not contain any characters that might be percent-encoded, as this would result in multiple URLs for the same content. By employing strict slugification and careful punctuation removal, the author was able to maintain a consistent and clean URL structure across all blog posts.",
  "summary": "Slug Generator: Cleaning Apostrophes, Ampersands and Trailing Hyphens Out of My Blog URLs Last month I moved 312 posts from an old WordPress site to Eleventy. The CMS export gave me titles exactly as the editors typed them: \"We're Open — 20% Off This Week & Next\", \"Don't Panic: A Developer's Guide to Production\". My one-liner title.lower().replace(\" \", \"-\") deployed without a single error and…",
  "key_points": [
    "Author cleaned 312 blog post URLs from special characters",
    "Python slugify library used for slug generation",
    "Node.js slugify package produced identical slugs to Python"
  ],
  "editors_take": "Automating the removal of special characters during a CMS migration ensures URL consistency and prevents the creation of duplicate links caused by percent-encoded characters in blog post titles.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}