FIX: Posts now render in reverse chronological order
This commit is contained in:
parent
d7fb16e24e
commit
b0fd1b6d9e
@ -16,10 +16,11 @@ export function addToDatabase(filePath: string, data: { [key: string]: any }, co
|
||||
const { title, date, readingTime, tags, excerpt } = data;
|
||||
|
||||
// Convert all values to strings or null explicitly (except tags)
|
||||
// Ensure date is stored in ISO format for consistent sorting
|
||||
const values = [
|
||||
filePath ? String(filePath) : null,
|
||||
title ? String(title) : null,
|
||||
date ? String(date) : null,
|
||||
date ? (date instanceof Date ? date.toISOString().split('T')[0] : String(date)) : null,
|
||||
readingTime ? String(readingTime) : null,
|
||||
excerpt ? String(excerpt) : null,
|
||||
content ? String(content) : null
|
||||
@ -156,7 +157,9 @@ export function calculateReadTime(content: string): number {
|
||||
|
||||
// Helper function to format date for display
|
||||
export function formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
// Parse ISO date string (YYYY-MM-DD)
|
||||
const date = new Date(dateString + 'T00:00:00');
|
||||
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
@ -170,7 +173,7 @@ export function getAdjacentPosts(currentPostPath: string) {
|
||||
SELECT path, title, date
|
||||
FROM posts
|
||||
WHERE path NOT LIKE '%.md'
|
||||
ORDER BY date ASC
|
||||
ORDER BY date DESC
|
||||
`);
|
||||
|
||||
const allPosts = allPostsQuery.all() as any[];
|
||||
@ -183,10 +186,10 @@ export function getAdjacentPosts(currentPostPath: string) {
|
||||
return { previousPost: null, nextPost: null };
|
||||
}
|
||||
|
||||
// Get previous post (newer date)
|
||||
// Get previous post (newer post, which comes before current in reverse chronological order)
|
||||
let previousPost = null;
|
||||
if (currentIndex < allPosts.length - 1) {
|
||||
const prevPost = allPosts[currentIndex + 1];
|
||||
if (currentIndex > 0) {
|
||||
const prevPost = allPosts[currentIndex - 1];
|
||||
// Clean up the path to match the URL structure
|
||||
const cleanPath = prevPost.path.replace(/^.*\/content\//, '/').replace(/\.md$/, '');
|
||||
previousPost = {
|
||||
@ -195,10 +198,10 @@ export function getAdjacentPosts(currentPostPath: string) {
|
||||
};
|
||||
}
|
||||
|
||||
// Get next post (older date)
|
||||
// Get next post (older post, which comes after current in reverse chronological order)
|
||||
let nextPost = null;
|
||||
if (currentIndex > 0) {
|
||||
const post = allPosts[currentIndex - 1];
|
||||
if (currentIndex < allPosts.length - 1) {
|
||||
const post = allPosts[currentIndex + 1];
|
||||
// Clean up the path to match the URL structure
|
||||
const cleanPath = post.path.replace(/^.*\/content\//, '/').replace(/\.md$/, '');
|
||||
nextPost = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user