From c493a0b21262b63b53682389d51f1840e037b692 Mon Sep 17 00:00:00 2001 From: RiseForever Date: Thu, 27 Aug 2026 23:39:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=92=E5=8A=A8=E5=8C=BA?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- src/components/EngagementTabs.astro | 231 ++++++++++++++++++++++++++++ src/components/TwikooClient.astro | 3 + src/components/TwikooComments.astro | 13 +- src/components/Webmentions.astro | 47 +++--- src/pages/posts/[...slug].astro | 10 +- 6 files changed, 267 insertions(+), 40 deletions(-) create mode 100644 src/components/EngagementTabs.astro diff --git a/.gitignore b/.gitignore index 123be91..309047e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ dist/ .env.* !.env.example pnpm-debug.log* -.obsidian/ \ No newline at end of file +.obsidian/ +.pnpm-store/ \ No newline at end of file diff --git a/src/components/EngagementTabs.astro b/src/components/EngagementTabs.astro new file mode 100644 index 0000000..dd20aab --- /dev/null +++ b/src/components/EngagementTabs.astro @@ -0,0 +1,231 @@ +--- +import TwikooComments from '@/components/TwikooComments.astro'; +import Webmentions from '@/components/Webmentions.astro'; +import { siteConfig } from '@/site.config'; + +interface Props { + commentsEnabled: boolean; + path: string; + target: string; +} + +const { commentsEnabled, path, target } = Astro.props; +const webmentionsEnabled = siteConfig.webmentions.enabled && Boolean(siteConfig.webmentions.endpoint.trim()); +const commentsConfigured = siteConfig.comments.provider === 'twikoo'; +const showComments = commentsEnabled && commentsConfigured; +--- + +{(webmentionsEnabled || showComments) &&
+ + + {webmentionsEnabled && } + + {showComments && } +
} + + + + diff --git a/src/components/TwikooClient.astro b/src/components/TwikooClient.astro index 2159a87..7d14cea 100644 --- a/src/components/TwikooClient.astro +++ b/src/components/TwikooClient.astro @@ -39,6 +39,8 @@ const initCurrentComments = () => { const root = document.querySelector('#twikoo-comments'); if (!(root instanceof HTMLElement) || root.dataset.twikooBound) return; + const panel = root.closest('[data-engagement-panel]'); + if (panel instanceof HTMLElement && panel.hidden) return; let config; try { config = JSON.parse(root.dataset.twikooConfig ?? '{}'); @@ -62,6 +64,7 @@ initCurrentComments(); document.addEventListener('astro:page-load', initCurrentComments); + document.addEventListener('engagement:tab-change', initCurrentComments); document.addEventListener('astro:before-swap', () => { document.querySelector('#twikoo-comments')?.replaceChildren(); }); diff --git a/src/components/TwikooComments.astro b/src/components/TwikooComments.astro index 8a58b9f..1e8e98f 100644 --- a/src/components/TwikooComments.astro +++ b/src/components/TwikooComments.astro @@ -12,12 +12,12 @@ const config = comments.provider === 'twikoo' && comments.envId.trim() ? { } : null; --- {enabled && config &&
-

评论

+

评论

} {enabled && !config &&
-

评论

+

评论

Twikoo 尚未配置

} diff --git a/src/components/Webmentions.astro b/src/components/Webmentions.astro index 2ab301c..1150b61 100644 --- a/src/components/Webmentions.astro +++ b/src/components/Webmentions.astro @@ -1,5 +1,4 @@ --- -import { Send } from '@lucide/astro'; import { getWebmentionEndpoint } from '@/lib/webmentions'; import { siteConfig } from '@/site.config'; @@ -25,7 +24,7 @@ const getEndpoint = endpoint ? getWebmentionEndpoint(endpoint, 'get') : ''; data-site-origin={new URL(siteConfig.site.url).origin} data-pagefind-ignore="all" > -

WebMention

+

WebMention

- +

} @@ -67,18 +63,8 @@ const getEndpoint = endpoint ? getWebmentionEndpoint(endpoint, 'get') : ''; diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 07cb800..d73a567 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -4,11 +4,10 @@ import BaseLayout from '@/layouts/BaseLayout.astro'; import Masthead from '@/components/Masthead.astro'; import { getContentCacheKey, getExcerpt, getPostCardImage, getPostPath, getPostTaxonomy, getPublicPosts, slugify } from '@/lib/content'; import { siteConfig } from '@/site.config'; -import TwikooComments from '@/components/TwikooComments.astro'; +import EngagementTabs from '@/components/EngagementTabs.astro'; import TableOfContents from '@/components/TableOfContents.astro'; import Mermaid from '@/components/Mermaid.astro'; import ImageLightbox from '@/components/ImageLightbox.astro'; -import Webmentions from '@/components/Webmentions.astro'; export async function getStaticPaths() { const posts = await getPublicPosts(); return posts.map((post, index) => ({ @@ -49,8 +48,11 @@ const dateText = `${date.year} 年 ${date.month} 月 ${date.day} 日`; {older ? 上一篇{older.data.title} : 上一篇没有更多了} {newer ? 下一篇{newer.data.title} : 下一篇没有更多了} - - +