Post card summaries built from markdown keep runs of spaces between blocks
Problem and intended result
Follow-up to #1280 (closed). A card summary produced by extractBodySummary in apps/blog/lib/post-summary.ts contains runs of several spaces where markdown blocks (headings, paragraphs, list items, emphasis) were joined. Because CardDescription in apps/blog/features/list-of-posts/summary.tsx is whitespace-pre-wrap, the runs show as wide gaps. Seen live at 390px on /blog/@sagarkothari88/posts on 2026-10-22: "HiveSuite Development Snaps Feed Scroll Improvements Reliable Scroll-to-Top Behavior Improved the scroll-to-top …". This affects every body-derived summary, as well as malformed descriptions cleaned since #1280 (closed).
The runs also make the summary use up its 200-character budget on whitespace.
Intended result: a summary from extractBodySummary has no run of more than one whitespace character, and no leading or trailing whitespace. A well-formed metadata description, which getPostSummary returns untouched, stays byte-identical.
Scope
In extractBodySummary, collapse whitespace runs to a single space after stripping URLs and before taking the first line and applying the length limit, so the limit counts visible text. Keep the existing first-line behaviour: if newlines matter for it, collapse only spaces and tabs ([ \t]+) and trim the selected line. Leave the whitespace-pre-wrap class and well-formed descriptions alone.
Regenerate any golden summaries (for example cardSummaries.expected.json) that change, from the recording via getPostSummary, not by hand.
Verification
- Unit tests in
apps/blog/lib/post-summary.test.ts: a body with a heading, a paragraph with emphasis and a list yields a summary with no double spaces. The HiveSuite-shaped malformed description from the #1280 (closed) tests has no double spaces and is still at most 200 characters. A well-formed description containing a double space is still returned unchanged. The new tests fail on the current code. - The card summary fixture specs pass with the regenerated golden file.