Skip to content

Conversation

Swizzzer
Copy link
Contributor

@Swizzzer Swizzzer commented Jul 3, 2025

Problem

The current template-generated archive/index.html seems to include the full post.body for each post. This causes the archive page size to grow significantly as the number of posts increases.

For example, with only 20 posts in my blog, the generated archive page was already 10 MB in size.

Solution

Since displaying the full post.body content is unnecessary on an archive page, I modified the template to exclude it. This change reduces the archive page size dramatically in my blog — from 10 MB to 70 KB — without affecting the page's functionality.

Copy link

vercel bot commented Jul 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuwari-yags ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 13, 2025 5:31am

@L4Ph
Copy link
Collaborator

L4Ph commented Jul 8, 2025

Could you send me a comparison of bundle sizes? I'd like to see actual improvement and verify if it's reproducible.

@Swizzzer
Copy link
Contributor Author

Swizzzer commented Jul 8, 2025

Could you send me a comparison of bundle sizes? I'd like to see actual improvement and verify if it's reproducible.

tested on my blog

Total size reduced

图片 图片

Archive page reduced

图片 图片

git diff

git diff cdeb a289 > changes.diff

diff --git a/src/pages/archive.astro b/src/pages/archive.astro
index 52ced04..181da5c 100644
--- a/src/pages/archive.astro
+++ b/src/pages/archive.astro
@@ -3,9 +3,9 @@ import ArchivePanel from "@components/ArchivePanel.svelte";
 import I18nKey from "@i18n/i18nKey";
 import { i18n } from "@i18n/translation";
 import MainGridLayout from "@layouts/MainGridLayout.astro";
-import { getSortedPosts } from "../utils/content-utils";
+import { getPostsForList } from "../utils/content-utils";
 
-const sortedPosts = await getSortedPosts();
+const sortedPosts = await getPostsForList();
 ---
 
 <MainGridLayout title={i18n(I18nKey.archive)}>
diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts
index a39a02f..b43fac1 100644
--- a/src/utils/content-utils.ts
+++ b/src/utils/content-utils.ts
@@ -1,4 +1,4 @@
-import { getCollection } from "astro:content";
+import { getCollection, type CollectionEntry } from "astro:content";
 import I18nKey from "@i18n/i18nKey";
 import { i18n } from "@i18n/translation";
 import { getCategoryUrl } from "@utils/url-utils.ts";
@@ -25,7 +25,21 @@ export async function getSortedPosts() {
 
 	return sorted;
 }
+export type PostForList = {
+    slug: string;
+    data: CollectionEntry<'posts'>['data'];
+}
+export async function getPostsForList(): Promise<PostForList[]> {
+    const sortedFullPosts = await getSortedPosts();
+    
+    // 映射到不包含 post.body 的新数组
+	const postsForClient = sortedFullPosts.map(post => ({
+		slug: post.slug,
+		data: post.data,
+	}));
 
+    return postsForClient;
+}
 export type Tag = {
 	name: string;
 	count: number;

@L4Ph
Copy link
Collaborator

L4Ph commented Jul 13, 2025

LGTM!!! @Swizzzer

@L4Ph L4Ph merged commit 3ff71d0 into saicaca:main Jul 13, 2025
6 checks passed
athena-sh pushed a commit to athena-sh/wayfinder.page that referenced this pull request Sep 10, 2025
…icaca#541)

* perf(content): ⚡️ reduce archive page size by stripping post body

* apply biome fix

* refactor: Separate function responsibilities (removed unnecessary linkage of preceding and following slugs)

---------

Co-authored-by: L4Ph <[email protected]>
athena-sh pushed a commit to athena-sh/wayfinder.page that referenced this pull request Oct 3, 2025
…icaca#541)

* perf(content): ⚡️ reduce archive page size by stripping post body

* apply biome fix

* refactor: Separate function responsibilities (removed unnecessary linkage of preceding and following slugs)

---------

Co-authored-by: L4Ph <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants