perf: aggregate homepage data and trim frontend loading

This commit is contained in:
2026-03-31 00:25:58 +08:00
parent 99b308e800
commit a9a05aa105
4 changed files with 137 additions and 18 deletions

View File

@@ -37,19 +37,13 @@ let apiError: string | null = null;
const { locale, t } = getI18n(Astro);
try {
const [settings, posts, rawTags, rawFriendLinks, nextCategories] = await Promise.all([
api.getSiteSettings(),
api.getPosts(),
api.getTags(),
api.getFriendLinks(),
api.getCategories(),
]);
const homeData = await api.getHomePageData();
siteSettings = settings;
allPosts = posts;
tags = rawTags.map(tag => tag.name);
friendLinks = rawFriendLinks.filter(friend => friend.status === 'approved');
categories = nextCategories;
siteSettings = homeData.siteSettings;
allPosts = homeData.posts;
tags = homeData.tags.map(tag => tag.name);
friendLinks = homeData.friendLinks.filter(friend => friend.status === 'approved');
categories = homeData.categories;
const filteredPosts = allPosts.filter(post => {
const normalizedCategory = post.category?.trim().toLowerCase() || '';