From d46f69c9a698781afa4ab8b510708f066116601f Mon Sep 17 00:00:00 2001 From: SepComet <202308010230@stu.csust.edu.cn> Date: Thu, 7 May 2026 09:09:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5=20Gitea=20?= =?UTF-8?q?Activity=20=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/fetch-gitea.ts | 24 +++++++++++- src/components/GiteaActivity.astro | 62 +++++++++++++++++++++++++++--- src/styles/global.css | 27 ++++++++++--- 3 files changed, 100 insertions(+), 13 deletions(-) diff --git a/scripts/fetch-gitea.ts b/scripts/fetch-gitea.ts index de7640c..54ba535 100644 --- a/scripts/fetch-gitea.ts +++ b/scripts/fetch-gitea.ts @@ -269,7 +269,7 @@ function mapActivityFeed( const repo = feed.repo?.full_name || fallback.fallbackRepo; const type = normalizeActivityType(feed.op_type); const message = - clean(feed.content) || + summarizeActivityMessage(feed.content) || clean(feed.comment?.body) || clean(feed.issue?.title) || clean(feed.pull_request?.title) || @@ -354,6 +354,28 @@ function clean(value?: string) { return value?.replace(/\s+/g, ' ').trim() || ''; } +function summarizeActivityMessage(value?: string) { + const cleaned = clean(value); + if (!cleaned.startsWith('{')) { + return cleaned; + } + + try { + const parsed = JSON.parse(cleaned) as { + HeadCommit?: { + Message?: string; + }; + Commits?: Array<{ + Message?: string; + }>; + }; + + return clean(parsed.HeadCommit?.Message) || clean(parsed.Commits?.[0]?.Message) || cleaned; + } catch { + return cleaned; + } +} + function trimTrailingSlash(value: string) { return value.replace(/\/+$/, ''); } diff --git a/src/components/GiteaActivity.astro b/src/components/GiteaActivity.astro index 481c5c4..8bbe41a 100644 --- a/src/components/GiteaActivity.astro +++ b/src/components/GiteaActivity.astro @@ -1,6 +1,7 @@ --- import type { GiteaActivityData } from '../data/loaders'; import { site } from '../config'; +import { formatDateTime } from '../utils/datetime'; import SyncMeta from './SyncMeta.astro'; interface Props { @@ -26,14 +27,63 @@ const heatmap = Array.from({ length: heatmapSize }, (_, index) => { ); }); -const recentActivities = activity.recent.slice(0, 3); +function cleanText(value?: string) { + return value?.replace(/\s+/g, ' ').trim() || ''; +} + +function summarizeActivity(item: GiteaActivityData['recent'][number]) { + const fallbackMessage = cleanText(item.message) || 'Repository activity'; + const fallbackTime = item.time; + + if (!fallbackMessage.startsWith('{')) { + return { + ...item, + message: fallbackMessage, + displayTime: formatDateTime(fallbackTime) || fallbackTime, + rawTime: fallbackTime, + }; + } + + try { + const parsed = JSON.parse(fallbackMessage) as { + HeadCommit?: { + Message?: string; + Timestamp?: string; + }; + Commits?: Array<{ + Message?: string; + Timestamp?: string; + }>; + }; + + const headCommit = parsed.HeadCommit ?? parsed.Commits?.[0]; + const message = cleanText(headCommit?.Message) || fallbackMessage; + const rawTime = headCommit?.Timestamp || fallbackTime; + + return { + ...item, + message, + displayTime: formatDateTime(rawTime) || rawTime, + rawTime, + }; + } catch { + return { + ...item, + message: fallbackMessage, + displayTime: formatDateTime(fallbackTime) || fallbackTime, + rawTime: fallbackTime, + }; + } +} + +const recentActivities = activity.recent.slice(0, 3).map(summarizeActivity); const isPlaceholder = activity.source === 'placeholder'; ---
- Gitea Activity + Gitea Activity

活跃度概览

{isPlaceholder @@ -84,16 +134,16 @@ const isPlaceholder = activity.source === 'placeholder'; recentActivities.length > 0 ? ( recentActivities.map((item) => (

- {item.repo} +

{item.repo}

{item.message}

-

- {item.time} +

+

)) ) : (
- 暂无同步活动 +

暂无同步活动

先运行一次 content:sync,或等待后续接入真实 Gitea 数据源。

) diff --git a/src/styles/global.css b/src/styles/global.css index 6dc6e52..91ee4c3 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -495,17 +495,22 @@ main { } .activity-panel .section-heading p, -.activity-panel .section-heading .eyebrow, .activity-panel .activity-copy, .activity-panel .activity-meta, .activity-panel .heatmap-legend { color: rgba(226, 232, 240, 0.86); } +.activity-panel__eyebrow { + border: 1px solid rgba(147, 197, 253, 0.28); + background: rgba(37, 99, 235, 0.18); + color: #eff6ff; +} + .activity-grid { display: grid; - grid-template-columns: 1.1fr 0.9fr; - gap: 1rem; + grid-template-columns: minmax(0, 1.3fr) minmax(18rem, 0.85fr); + gap: 1.25rem; align-items: start; } @@ -545,19 +550,29 @@ main { .activity-list { display: grid; gap: 0.75rem; + min-width: 0; } .activity-item { + min-width: 0; padding: 0.95rem 1rem; border: 1px solid rgba(148, 163, 184, 0.22); border-radius: 1rem; background: rgba(15, 23, 42, 0.32); } -.activity-item strong { - display: block; - margin-bottom: 0.25rem; +.activity-item__repo { + margin: 0 0 0.35rem; color: #fff; + font-size: 0.84rem; +} + +.activity-panel .activity-copy { + overflow-wrap: anywhere; +} + +.activity-item__meta { + margin-top: 0.55rem; } .corner-gallery {