diff --git a/app.js b/app.js index 2e028f9..868ff4f 100644 --- a/app.js +++ b/app.js @@ -71,6 +71,13 @@ function slugToTitle(slug) { function getAllBlogPosts(page = 1, postsPerPage = 5) { const blogFiles = fs.readdirSync(path.join(__dirname, 'markdown')).filter(file => file.endsWith('.md')); + // Sort by birthtime (latest first) like in your RSS feed + blogFiles.sort((a, b) => { + const statA = fs.statSync(path.join(__dirname, 'markdown', a)).birthtime; + const statB = fs.statSync(path.join(__dirname, 'markdown', b)).birthtime; + return statB - statA; // Descending order, latest first + }); + // Paginate the results const totalPosts = blogFiles.length; const totalPages = Math.ceil(totalPosts / postsPerPage); @@ -83,24 +90,18 @@ function getAllBlogPosts(page = 1, postsPerPage = 5) { const title = file.replace('.md', '').replace(/-/g, ' '); // Keep original casing for title const slug = titleToSlug(title); // Convert title to slug (lowercase) - // Get the last modified date of the markdown file + // Get the creation time of the markdown file const stats = fs.statSync(path.join(__dirname, 'markdown', file)); - const dateCreated = new Date(stats.birthtime); // Use birthtime for last modification time - - // Format the date - const formattedDate = dateCreated.toLocaleDateString('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric' - }); + const dateCreated = new Date(stats.birthtime); // Use birthtime for sorting and displaying return { - title, // Original casing title + title, slug, - date: formattedDate // Include the formatted date + dateCreated, // Keep as Date object for sorting }; }); + // Return the paginated and sorted blog posts and the total pages return { blogPosts, totalPages }; } diff --git a/views/index.ejs b/views/index.ejs index 112e0a9..a30ff0b 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -37,22 +37,30 @@

Where Technology Meets Creativity: Insights from a Linux Enthusiast

- +

Recent Posts

- +
+
+