refactor: 优化文章摘要生成逻辑并移除多余的阅读全文链接

This commit is contained in:
seahi committed 2026-07-29 21:10:35 +08:00
1 parent de02716e11
commit 0a0f921040
2 files changed
+14 -3

No files matched your search

+13 -2
View File
@@ -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('<!--more-->');
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
+1 -1
View File
@@ -18,7 +18,7 @@
<time>{post.date}</time>
</div>
<h1 class="title">{post.title}</h1>
<p class="excerpt">{post.excerpt} | <span class="full-link">阅读全文</span></p>
<p class="excerpt">{post.excerpt}</p>
</div>
</article>
</a>