Fix date and read time on Blog Posts
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -57,7 +57,7 @@ function PostCard({ post }: { post: Post }) {
|
||||
<div className="post-card-meta">
|
||||
<time dateTime={post.date}>{formattedDate}</time>
|
||||
<span className="meta-separator">•</span>
|
||||
<span className="read-time">5 min read</span>
|
||||
<span className="read-time">{post.readingTime} min read</span>
|
||||
</div>
|
||||
{tags.length > 0 && (
|
||||
<div className="post-card-tags">
|
||||
|
||||
@@ -47,7 +47,7 @@ export function Post({ children, meta }: PostProps) {
|
||||
{meta.readingTime &&
|
||||
<>
|
||||
<span className="meta-separator">•</span>
|
||||
<span>{meta.readingTime}</span>
|
||||
<span>{meta.readingTime} min read</span>
|
||||
</>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user