nicholai-work-2026/src/utils/reading-time.ts
Nicholai adf3f376ba Add search with lunr and read time to site
- Add lunr dependency to package.json and pnpm-lock.yaml.
- Implement SearchDialog component for full‑text search using lunr.
- Add readTime prop to BlogCard with default 5 min read.
- Add reading‑time utility for estimated read duration.
- Update layout and page components to include new props.
- Generate search.json data for indexing.

Hubert The Eunuch
2025-12-24 03:48:51 -07:00

12 lines
478 B
TypeScript

/**
* Calculate reading time for a given text content
* @param content - The text content to analyze
* @param wordsPerMinute - Reading speed (default: 200 wpm)
* @returns Reading time string (e.g., "5 min read")
*/
export function calculateReadingTime(content: string, wordsPerMinute: number = 200): string {
const wordCount = content?.split(/\s+/).length || 0;
const readingTime = Math.max(1, Math.ceil(wordCount / wordsPerMinute));
return `${readingTime} min read`;
}