@bernierllc/content-type-blog-post
Version:
Blog post content type with rich TipTap editor, SEO metadata, database storage, and web publishing
30 lines (26 loc) • 1.03 kB
text/typescript
/*
Copyright (c) 2025 Bernier LLC
This file is licensed to the client under a limited-use license.
The client may use and modify this code *only within the scope of the project it was delivered for*.
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
*/
/**
* Calculate word count from HTML content
* @param content - HTML content string
* @returns Word count
*/
export function calculateWordCount(content: string): number {
// Remove HTML tags and count words
const text = content.replace(/<[^>]*>/g, ' ');
const words = text.trim().split(/\s+/);
return words.filter((word) => word.length > 0).length;
}
/**
* Calculate reading time from word count
* @param wordCount - Number of words
* @param wordsPerMinute - Average reading speed (default: 200)
* @returns Reading time in minutes
*/
export function calculateReadingTime(wordCount: number, wordsPerMinute: number = 200): number {
return Math.ceil(wordCount / wordsPerMinute);
}