diff options
| author | aman333nolawz <amananudhiu@gmail.com> | 2026-03-02 21:49:13 +0530 |
|---|---|---|
| committer | aman333nolawz <amananudhiu@gmail.com> | 2026-03-02 21:49:13 +0530 |
| commit | d41eff9eccf66644c4c60f53cb516bf079937a28 (patch) | |
| tree | 248a0863a3181369f943d678ec4273911d35efac /src/lib/utils.ts | |
Using astro-erudite for static site generation
Diffstat (limited to 'src/lib/utils.ts')
| -rw-r--r-- | src/lib/utils.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts new file mode 100644 index 0000000..d4d8119 --- /dev/null +++ b/src/lib/utils.ts @@ -0,0 +1,37 @@ +import { type ClassValue, clsx } from 'clsx' +import { twMerge } from 'tailwind-merge' + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)) +} + +export function formatDate(date: Date) { + return Intl.DateTimeFormat('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + }).format(date) +} + +export function calculateWordCountFromHtml( + html: string | null | undefined, +): number { + if (!html) return 0 + const textOnly = html.replace(/<[^>]+>/g, '') + return textOnly.split(/\s+/).filter(Boolean).length +} + +export function readingTime(wordCount: number): string { + const readingTimeMinutes = Math.max(1, Math.round(wordCount / 200)) + return `${readingTimeMinutes} min read` +} + +export function getHeadingMargin(depth: number): string { + const margins: Record<number, string> = { + 3: 'ml-4', + 4: 'ml-8', + 5: 'ml-12', + 6: 'ml-16', + } + return margins[depth] || '' +} |
