chapter-word-count.ts 321 B

12345678
  1. import { parseFrontmatter } from "@/lib/frontmatter"
  2. export function countChapterBodyWords(markdown: string): number {
  3. const { body } = parseFrontmatter(markdown)
  4. const withoutHeading = body.replace(/^#\s+.+?(?:\r?\n|$)/, "")
  5. const normalized = withoutHeading.replace(/[\s ]+/g, "")
  6. return normalized.length
  7. }