EU Parliament Monitor — API Documentation - v0.9.25
    Preparing search index...

    Module Aggregator/Metadata/DescriptionFinalization

    Script-aware terminator + ellipsis-scrub helpers extracted from resolve-helpers.ts so that module stays below the 600-line drift-guard cap (see test/unit/source-file-size.test.js). Pure leaf module — depends only on the script-family classifier from seo-budgets.ts.

    Background. Two SEO-extraction regressions repeatedly hit this code path and motivated extracting it as its own module:

    • clampForBudget (and truncateDescription) emit a trailing when they have to hard-cut mid-clause — the executive-brief-seo-extraction.test.js description-ellipsis gate (and title-rejection.ts::looksLikeEllipsisCut) flag those as truncation cuts. We scrub the ellipsis here and either back-scan to the most recent real terminator within the trailing ~35 chars, or append a script-appropriate sentence terminator (. for Latin / RTL, for CJK).
    • The second clamp in the HTML shell can knock the terminator off when the description sits exactly at the per-script budget. The maxLength reservation in ensureDescriptionTerminator fixes a live 2026-05-26 regression where news/2026-05-26-breaking-fr.html shipped a mid-word cut after the terminator was dropped.

    Functions

    appendTerminator
    ensureTerminator
    scrubTrailingEllipsis
    ensureDescriptionTerminator