From 134bbb4d7629bc3f0fd73d45a9749514618c089e Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Fri, 4 Jul 2025 16:11:07 +0800 Subject: [PATCH] feat: sanitize and clamp home article description --- open-isle-cli/src/utils/markdown.js | 7 +++++++ open-isle-cli/src/views/HomePageView.vue | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/open-isle-cli/src/utils/markdown.js b/open-isle-cli/src/utils/markdown.js index 061d8b73b..774b60d1f 100644 --- a/open-isle-cli/src/utils/markdown.js +++ b/open-isle-cli/src/utils/markdown.js @@ -9,3 +9,10 @@ const md = new MarkdownIt({ export function renderMarkdown(text) { return md.render(text || '') } + +export function stripMarkdown(text) { + const html = md.render(text || '') + const el = document.createElement('div') + el.innerHTML = html + return el.textContent || el.innerText || '' +} diff --git a/open-isle-cli/src/views/HomePageView.vue b/open-isle-cli/src/views/HomePageView.vue index 8d636f888..205f0b2ee 100644 --- a/open-isle-cli/src/views/HomePageView.vue +++ b/open-isle-cli/src/views/HomePageView.vue @@ -24,7 +24,7 @@ {{ article.title }} -
{{ article.description }}
+
{{ sanitizeDescription(article.description) }}
@@ -62,6 +62,7 @@ @@ -281,6 +284,10 @@ L 站的愿景是成为新的**理想型社区**,让每一个一身疲惫的 margin-top: 10px; font-size: 14px; color: gray; + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; } .article-info-container {