优化首页 Gitea Activity 展示
This commit is contained in:
+23
-1
@@ -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(/\/+$/, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user