--- import BlogLayout from '../../../layouts/BlogLayout.astro'; import BlogList from '../../../components/blog/BlogList.astro'; import CategoryCard from '../../../components/blog/CategoryCard.astro'; import TagCard from '../../../components/blog/TagCard.astro'; import Container from '../../../components/ui/Container'; import { type BlogPost } from '@/types'; import { type Lang } from '@/i18n/utils'; import { defaultLang } from '@/i18n/ui'; import { sortPostsByDate, extractCategories, extractTags } from '@/utils/blog-utils'; // 使用Astro.currentLocale获取当前语言环境 const lang = Astro.currentLocale as Lang || defaultLang; // 使用import.meta.glob读取所有中文博客文章 const allPosts = await import.meta.glob('./posts/*.md', { eager: true }); // 处理博客文章数据 const blogPosts: BlogPost[] = Object.values(allPosts).map((post: any) => { const slug = post.url?.split('/').filter(Boolean).pop() || ''; // 获取文章的默认图片,如果frontmatter中没有指定 const defaultImage = "https://images.unsplash.com/photo-1516321318423-f06f85e504b3?w=400&h=250&fit=crop&crop=center"; return { title: post.frontmatter.title, description: post.frontmatter.description || '', image: post.frontmatter.image || defaultImage, slug: slug, tags: post.frontmatter.tags || [], tagId: post.frontmatter.tagId || [], category: Array.isArray(post.frontmatter.category) ? post.frontmatter.category : post.frontmatter.category ? [post.frontmatter.category] : [], categoryId: Array.isArray(post.frontmatter.categoryId) ? post.frontmatter.categoryId : post.frontmatter.categoryId ? [post.frontmatter.categoryId] : [], date: post.frontmatter.date || post.frontmatter.pubDate || '', readTime: post.frontmatter.readTime || post.frontmatter.readingTime || '5分钟阅读', }; }); // 使用工具函数按日期排序 const sortedBlogPosts = sortPostsByDate(blogPosts); // 提取所有文章的分类和标签信息(用于侧边栏) const allPostsArray = Object.values(allPosts).map((post: any) => ({ category: post.frontmatter.category || [], categoryId: post.frontmatter.categoryId || [], tags: post.frontmatter.tags || [], tagId: post.frontmatter.tagId || [] })); // 使用工具函数提取分类和标签 const categories = extractCategories(allPostsArray); const tags = extractTags(allPostsArray); --- 我的博客 深入我对编程、技术趋势和开发者生活的思考。探索我的最新文章。
深入我对编程、技术趋势和开发者生活的思考。探索我的最新文章。