Fix date and read time on Blog Posts
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { Database } from 'bun:sqlite';
|
import { Database } from 'bun:sqlite';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { calculateReadTime } from '../frontend/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton database connection class for managing blog posts and tags
|
* Singleton database connection class for managing blog posts and tags
|
||||||
@@ -101,7 +102,7 @@ class DatabaseConnection {
|
|||||||
filePath ? String(filePath) : null,
|
filePath ? String(filePath) : null,
|
||||||
title ? String(title) : null,
|
title ? String(title) : null,
|
||||||
date ? (date instanceof Date ? date.toISOString().split('T')[0] : String(date)) : 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,
|
excerpt ? String(excerpt) : null,
|
||||||
content ? String(content) : null
|
content ? String(content) : null
|
||||||
];
|
];
|
||||||
@@ -269,15 +270,7 @@ class DatabaseConnection {
|
|||||||
|
|
||||||
// Add tags to each post and clean up paths
|
// Add tags to each post and clean up paths
|
||||||
return posts.map(post => {
|
return posts.map(post => {
|
||||||
const basePost = post satisfies {
|
const basePost = { ...post, readingTime: post.reading_time}
|
||||||
id: number,
|
|
||||||
path: string,
|
|
||||||
title: string,
|
|
||||||
date: string,
|
|
||||||
readingTime: string,
|
|
||||||
summary: string,
|
|
||||||
content: string
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...basePost,
|
...basePost,
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function PostCard({ post }: { post: Post }) {
|
|||||||
<div className="post-card-meta">
|
<div className="post-card-meta">
|
||||||
<time dateTime={post.date}>{formattedDate}</time>
|
<time dateTime={post.date}>{formattedDate}</time>
|
||||||
<span className="meta-separator">•</span>
|
<span className="meta-separator">•</span>
|
||||||
<span className="read-time">5 min read</span>
|
<span className="read-time">{post.readingTime} min read</span>
|
||||||
</div>
|
</div>
|
||||||
{tags.length > 0 && (
|
{tags.length > 0 && (
|
||||||
<div className="post-card-tags">
|
<div className="post-card-tags">
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ interface PostProps {
|
|||||||
|
|
||||||
export function Post({ children, meta }: PostProps) {
|
export function Post({ children, meta }: PostProps) {
|
||||||
const { previousPost, nextPost } = meta;
|
const { previousPost, nextPost } = meta;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<article className="blog-post">
|
<article className="blog-post">
|
||||||
@@ -47,7 +47,7 @@ export function Post({ children, meta }: PostProps) {
|
|||||||
{meta.readingTime &&
|
{meta.readingTime &&
|
||||||
<>
|
<>
|
||||||
<span className="meta-separator">•</span>
|
<span className="meta-separator">•</span>
|
||||||
<span>{meta.readingTime}</span>
|
<span>{meta.readingTime} min read</span>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ export function calculateReadTime(content: string): number {
|
|||||||
|
|
||||||
// Helper function to format date for display
|
// Helper function to format date for display
|
||||||
export function formatDate(dateString: string): string {
|
export function formatDate(dateString: string): string {
|
||||||
// Parse ISO date string (YYYY-MM-DD)
|
// Parse ISO date string (YYYY-MM-DD)unique
|
||||||
const date = new Date(dateString + 'T00:00:00');
|
const date = new Date(dateString);
|
||||||
|
|
||||||
return date.toLocaleDateString('en-US', {
|
return date.toLocaleDateString('en-US', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
|
|||||||
Reference in New Issue
Block a user