- 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
12 lines
478 B
TypeScript
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`;
|
|
}
|