diff --git a/src/db/index.ts b/src/db/index.ts index 5ebbdd2..a24d21e 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,5 +1,6 @@ import { Database } from 'bun:sqlite'; import path from 'path'; +import { calculateReadTime } from '../frontend/utils'; /** * Singleton database connection class for managing blog posts and tags @@ -101,7 +102,7 @@ class DatabaseConnection { filePath ? String(filePath) : null, title ? String(title) : null, date ? (date instanceof Date ? date.toISOString().split('T')[0] : String(date)) : null, - readingTime ? String(readingTime) : null, + readingTime ? String(readingTime) : calculateReadTime(content), excerpt ? String(excerpt) : null, content ? String(content) : null ]; @@ -269,15 +270,7 @@ class DatabaseConnection { // Add tags to each post and clean up paths return posts.map(post => { - const basePost = post satisfies { - id: number, - path: string, - title: string, - date: string, - readingTime: string, - summary: string, - content: string - }; + const basePost = { ...post, readingTime: post.reading_time} return { ...basePost, diff --git a/src/frontend/pages/home.tsx b/src/frontend/pages/home.tsx index 3dce94c..68fb0b0 100644 --- a/src/frontend/pages/home.tsx +++ b/src/frontend/pages/home.tsx @@ -57,7 +57,7 @@ function PostCard({ post }: { post: Post }) {
- 5 min read + {post.readingTime} min read
{tags.length > 0 && (
diff --git a/src/frontend/pages/post.tsx b/src/frontend/pages/post.tsx index e0691aa..bc12169 100644 --- a/src/frontend/pages/post.tsx +++ b/src/frontend/pages/post.tsx @@ -19,7 +19,7 @@ interface PostProps { export function Post({ children, meta }: PostProps) { const { previousPost, nextPost } = meta; - + return (
@@ -47,7 +47,7 @@ export function Post({ children, meta }: PostProps) { {meta.readingTime && <> - {meta.readingTime} + {meta.readingTime} min read }
diff --git a/src/frontend/utils.ts b/src/frontend/utils.ts index ac01cd4..c6e91b3 100644 --- a/src/frontend/utils.ts +++ b/src/frontend/utils.ts @@ -26,8 +26,8 @@ export function calculateReadTime(content: string): number { // Helper function to format date for display export function formatDate(dateString: string): string { - // Parse ISO date string (YYYY-MM-DD) - const date = new Date(dateString + 'T00:00:00'); + // Parse ISO date string (YYYY-MM-DD)unique + const date = new Date(dateString); return date.toLocaleDateString('en-US', { year: 'numeric',