Merge origin/master

This commit is contained in:
2026-01-25 19:45:41 +01:00
433 changed files with 77968 additions and 36839 deletions
+26 -6
View File
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import { cache } from '@/utils/cache';
export interface BlogPost {
slug: string;
@@ -155,6 +156,14 @@ function parseMarkdownPost(filename: string, content: string): BlogPost | null {
}
export function getAllBlogPosts(): BlogPost[] {
const cacheKey = 'blog:all-posts';
// Check cache first
const cachedPosts = cache.get<BlogPost[]>(cacheKey);
if (cachedPosts) {
return cachedPosts;
}
if (!fs.existsSync(BLOG_POSTS_DIR)) {
console.warn('Blog posts directory not found:', BLOG_POSTS_DIR);
return [];
@@ -167,16 +176,27 @@ export function getAllBlogPosts(): BlogPost[] {
const posts: BlogPost[] = [];
for (const file of files) {
const filePath = path.join(BLOG_POSTS_DIR, file);
const content = fs.readFileSync(filePath, 'utf-8');
const post = parseMarkdownPost(file, content);
if (post) {
posts.push(post);
try {
const filePath = path.join(BLOG_POSTS_DIR, file);
const content = fs.readFileSync(filePath, 'utf-8');
const post = parseMarkdownPost(file, content);
if (post) {
posts.push(post);
}
} catch (error) {
// Skip files that fail to parse
console.warn(`Failed to parse blog post: ${file}`, error);
continue;
}
}
// Sort by date descending (newest first)
return posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
const sortedPosts = posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
// Cache the results
cache.set(cacheKey, sortedPosts);
return sortedPosts;
}
export function getBlogPostBySlug(slug: string): BlogPost | null {