From 0a0f9210405a3cb20ced5af55f2fb70b0f051e28 Mon Sep 17 00:00:00 2001 From: seaHi Date: Wed, 29 Jul 2026 21:10:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E6=91=98=E8=A6=81=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B9=B6=E7=A7=BB=E9=99=A4=E5=A4=9A=E4=BD=99=E7=9A=84=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E5=85=A8=E6=96=87=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/+page.server.ts | 15 +++++++++++++-- src/routes/+page.svelte | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index b7a7693..6de9ad8 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -40,12 +40,23 @@ export const load: PageServerLoad = async ({ platform }) => { const year = d.getFullYear(); let excerpt = ''; - const contentStr = post.content as string || ''; + let contentStr = post.content as string || ''; + + // Filter out Hugo shortcodes like {{< admonition abstract "标题" >}} + contentStr = contentStr.replace(/\{\{<[\s\S]*?>\}\}/g, ''); + const parts = contentStr.split(''); if (parts.length > 1) { excerpt = parts[0].trim(); } else { - excerpt = contentStr.replace(/[#*\`>~\\[\\]\\(\\)\\-]/g, '').substring(0, 150) + (contentStr.length > 150 ? '...' : ''); + // Strip basic markdown syntax for the automatic excerpt + let plainText = contentStr.replace(/[#*\`>~\\[\\]\\(\\)\\-]/g, '').trim(); + excerpt = plainText.substring(0, 150).trim(); + } + + // Append ... to indicate there is more to read + if (excerpt && !excerpt.endsWith('...')) { + excerpt += '...'; } // Do not send full content to the list view to save bandwidth diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 256e2cb..5c82df6 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -18,7 +18,7 @@

{post.title}

-

{post.excerpt} | 阅读全文

+

{post.excerpt}