优化首页 Gitea Activity 展示

This commit is contained in:
SepComet
2026-05-07 09:09:29 +08:00
parent 31796260cc
commit d46f69c9a6
3 changed files with 100 additions and 13 deletions
+23 -1
View File
@@ -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(/\/+$/, '');
}