namespaceSummary

tcmts.share.namespaceSummary · #2wxochih · term · runs anywhere

A namespace's description: the first paragraph of the README in it, or of its own doc.

import type { Share } from "#codebase/tcmts/share";
import type { NameRow } from "#codebase/tcmts/store";

export function namespaceSummary(s: Share, rows: NameRow[], ns: string): string {
  const readme = rows.find((r) => r.path === `${ns}.README` && r.kind === "file");
  if (!readme) return "";
  const text = s.cb.store.getDef(readme.hash)?.sourceText ?? "";
  const para = text
    .split(/\n\s*\n/)
    .map((p) => p.trim())
    .find((p) => p && !p.startsWith("#") && !p.startsWith("```"));
  return (para ?? "")
    .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
    .replace(/[*_`]/g, "")
    .replace(/\s+/g, " ")
    .slice(0, 160);
}

uses

used by