Skip to the content.
Building a Robust SEO Slug Compiler | AI Systems Design From Scratch

Connect with Amin Boulouma Official

🏠 Documentation Hub 📝 Engineering Blog 💻 GitHub Repository

SEO Slug Compilers: Standardizing Filenames

Amin Boulouma, Software Engineer

For static site generators like Jekyll, the post filename is not just metadata, it is the URL structure. A proper filename must adhere to strict rules: no special characters, no spaces, and standardized date-prefixing. The ResilientSlugGenerator and JekyllFilenameController classes demonstrate a professional-grade pipeline for this task.

The Normalization Pipeline

The conversion process is a multi-stage “purification” pipeline. Every step ensures the output becomes increasingly compliant with web URL standards.

  1. Unicode Decomposition (NFKD): This is the most crucial step. It breaks down complex characters (like Ă©) into their base characters (e) and combining accents, allowing them to be stripped during the ASCII conversion phase.
  2. ASCII Sanitization: Stripping non-ASCII characters ensures your URLs work across all browsers and server environments without encoding issues.
  3. Regex Purging: We use re.sub(r'[^\w\s-]', '', text) to remove any character that is not a word character (letters, numbers, underscores), a space, or a hyphen.
  4. Token Normalization: Finally, we collapse multiple spaces or hyphens into a single hyphen delimiter (-), resulting in clean tokens like this-is-my-post.

Architectural Workflow: Jekyll Controller

The JekyllFilenameController encapsulates this logic and adds filesystem context, specifically, the date-prefix requirement (e.g., YYYY-MM-DD-slug.md).

The Slug Transformation Core

def transform_to_slug(self, text: str) -> str:
    # 1. Normalize unicode to standard ASCII
    text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('ascii')
    # 2. Lowercase and strip invalid characters
    text = re.sub(r'[^\w\s-]', '', text.lower()).strip()
    # 3. Collapse whitespace to single hyphens
    return re.sub(r'[-\s]+', '-', text).strip('-')

Best Practices

By decomposing your slug generation into these modular steps, you create a system that is easily testable, highly predictable, and perfectly suited for automation.

Connect with Amin Boulouma Official