A calm place to write long-form, and publish it to the open social web.
skypress.blog/
1/**
2 * A brief plain-text excerpt for a document/card description (the og:description fallback).
3 * Collapses runs of whitespace to single spaces, cuts on a word boundary at or before
4 * `maxChars`, and appends an ellipsis when it had to truncate. Returns '' for empty or
5 * whitespace-only input. Pure + dependency-free (no `@wordpress/*`, no network) so it is
6 * safe in BOTH the server reader and the browser publisher (AGENTS.md §3).
7 */
8export function deriveExcerpt( text: string, maxChars = 200 ): string {
9 const normalized = text.replace( /\s+/g, ' ' ).trim();
10 if ( normalized.length <= maxChars ) {
11 return normalized;
12 }
13 const slice = normalized.slice( 0, maxChars );
14 const lastSpace = slice.lastIndexOf( ' ' );
15 const cut = lastSpace > 0 ? slice.slice( 0, lastSpace ) : slice;
16 return `${ cut.trimEnd() }…`;
17}