forked from projectbluefin/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeedItems.tsx
More file actions
326 lines (298 loc) · 11.1 KB
/
FeedItems.tsx
File metadata and controls
326 lines (298 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import React from "react";
import useStoredFeed from "@theme/useStoredFeed";
import styles from "./FeedItems.module.css";
import {
PACKAGE_PATTERNS,
extractVersionChange,
} from "../config/packageConfig";
interface FeedItemsProps {
feedId: string;
title: string;
maxItems?: number;
showDescription?: boolean;
filter?: (item: FeedItem) => boolean;
}
interface VersionChange {
name: string;
change: string;
}
// Local type definitions that match src/types/theme.d.ts
// These must be kept in sync with the module declaration
interface FeedItem {
title: string;
link:
| string
| { href?: string }
| Array<{
href?: string;
rel?: string;
$?: { href?: string; type?: string };
}>;
description?: string;
pubDate?: string;
updated?: string;
guid?: string;
id?: string;
author?: string | { name?: string };
content?: { value?: string } | string;
}
interface ParsedFeed {
// RSS feed structure
rss?: {
channel?: {
item?: FeedItem | FeedItem[];
};
};
// Alternative RSS structure
channel?: {
item?: FeedItem | FeedItem[];
};
// Atom feed structure
feed?: {
entry?: FeedItem | FeedItem[];
};
}
// Helper function to format date in long form
const formatLongDate = (dateString: string): string => {
const date = new Date(dateString);
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
};
// Helper function to extract key version changes from changelog content
const extractVersionSummary = (content: string): VersionChange[] => {
const changes: VersionChange[] = [];
if (!content) return changes;
// Use centralized package configuration
for (const packageConfig of PACKAGE_PATTERNS) {
const versionChange = extractVersionChange(content, packageConfig);
if (versionChange) {
changes.push(versionChange);
}
}
return changes;
};
// Helper function to determine if a feed should show executive summaries
const isReleaseFeed = (feedId: string): boolean => {
return feedId === "bluefinReleases" || feedId === "bluefinLtsReleases";
};
// Helper function to format release titles for better readability
const formatReleaseTitle = (title: string, feedId: string): string => {
if (feedId === "bluefinLtsReleases") {
// For LTS releases: Remove "bluefin-lts LTS: " or "Bluefin LTS: " prefix
// Example: "bluefin-lts LTS: 20250910 (c10s, #cfd65ad)" -> "20250910 (c10s, #cfd65ad)"
// Example: "Bluefin LTS: 20250808 (c10s)" -> "20250808 (c10s)"
return title.replace(/^(bluefin-lts|Bluefin) LTS: /, "");
} else if (feedId === "bluefinReleases") {
// For stable releases: Remove "stable-" prefix and ": Stable" text, simplify Fedora version
// Example: "stable-20250907: Stable (F42.20250907, #921e6ba)" -> "20250907 (F42 #921e6ba)"
if (title.startsWith("stable-")) {
return title.replace(
/^stable-([^:]+): Stable \(F(\d+)\.\d+, (#[^)]+)\)$/,
"$1 (F$2 $3)",
);
}
// For GTS releases: Remove "gts-" prefix and ": Gts" text, simplify Fedora version
// Example: "gts-20250907: Gts (F41.20250907, #921e6ba)" -> "20250907 (F41 #921e6ba)"
else if (title.startsWith("gts-")) {
return title.replace(
/^gts-([^:]+): Gts \(F(\d+)\.\d+, (#[^)]+)\)$/,
"$1 (F$2 $3)",
);
}
}
// Return original title if no formatting rules apply
return title;
};
const FeedItems: React.FC<FeedItemsProps> = ({
feedId,
title,
maxItems = 5,
showDescription = false,
filter,
}) => {
try {
const feedData: ParsedFeed = useStoredFeed(feedId);
// Handle different RSS/Atom feed structures
let items: FeedItem[] = [];
if (feedData?.rss?.channel?.item) {
items = Array.isArray(feedData.rss.channel.item)
? feedData.rss.channel.item
: [feedData.rss.channel.item];
} else if (feedData?.channel?.item) {
items = Array.isArray(feedData.channel.item)
? feedData.channel.item
: [feedData.channel.item];
} else if (feedData?.feed?.entry) {
items = Array.isArray(feedData.feed.entry)
? feedData.feed.entry
: [feedData.feed.entry];
}
// Apply filter if provided
if (filter) {
items = items.filter(filter);
}
// Limit items to maxItems
const displayItems = items.slice(0, maxItems);
if (displayItems.length === 0) {
return (
<div className={styles.feedContainer}>
<h3 className={styles.feedTitle}>{title}</h3>
<p className={styles.noItems}>No items available</p>
</div>
);
}
return (
<div className={styles.feedContainer}>
<h3 className={styles.feedTitle}>{title}</h3>
<ul className={styles.feedList}>
{displayItems.map((item, index) => {
// Extract values handling both RSS and Atom formats
let itemLink = "";
// First try to get link from the link field
if (typeof item.link === "string" && item.link) {
itemLink = item.link;
} else if (item.link && typeof item.link === "object") {
// Handle Atom link structure - could be an array or object
if (Array.isArray(item.link)) {
// For GitHub Atom feeds, look for type="text/html" first, then fall back to rel="alternate"
const htmlLink =
item.link.find((l) => l.$ && l.$.type === "text/html") ||
item.link.find((l) => l.rel === "alternate") ||
item.link[0];
itemLink = htmlLink?.href || htmlLink?.$.href || "";
} else {
itemLink = item.link.href || "";
}
}
// If no link found, try to construct it from GitHub Atom feed ID format
if (!itemLink && item.id && typeof item.id === "string") {
// GitHub Atom feed IDs look like: "tag:github.com,2008:Repository/611397346/stable-20250907"
const idMatch = item.id.match(
/^tag:github\.com,\d+:Repository\/(\d+)\/(.+)$/,
);
if (idMatch) {
const [, repoId, tag] = idMatch;
// For GitHub releases, we need to determine the repo name from the feedId
if (feedId === "bluefinReleases") {
itemLink = `https://github.com/ublue-os/bluefin/releases/tag/${tag}`;
} else if (feedId === "bluefinLtsReleases") {
itemLink = `https://github.com/ublue-os/bluefin-lts/releases/tag/${tag}`;
}
} else {
// Try to match GitHub Discussion IDs
// Format: "tag:github.com,2008:Discussion/12345"
const discussionMatch = item.id.match(
/^tag:github\.com,\d+:Discussion\/(\d+)$/,
);
if (discussionMatch) {
const [, discussionId] = discussionMatch;
if (
feedId === "bluefinDiscussions" ||
feedId === "bluefinAnnouncements"
) {
itemLink = `https://github.com/ublue-os/bluefin/discussions/${discussionId}`;
}
}
}
}
const itemDate = item.pubDate || item.updated;
const itemAuthor =
typeof item.author === "string" ? item.author : item.author?.name;
// No individual authors displayed for release feeds - moved to section level
const itemDescription =
item.description ||
(typeof item.content === "object"
? item.content?.value
: item.content);
const itemId = item.guid || item.id || itemLink || index;
// Extract executive summary for release feeds
const versionSummary =
isReleaseFeed(feedId) && itemDescription
? extractVersionSummary(itemDescription)
: [];
// Format the title for better readability
const displayTitle = formatReleaseTitle(item.title, feedId);
return (
<li key={itemId} className={styles.feedItem}>
{itemLink ? (
<a
href={itemLink}
target="_blank"
rel="noopener noreferrer"
className={styles.feedItemLink}
>
<div className={styles.feedItemContent}>
<h4 className={styles.feedItemTitle}>{displayTitle}</h4>
{itemDate && (
<time className={styles.feedItemDate}>
{formatLongDate(itemDate)}
</time>
)}
{versionSummary.length > 0 && (
<ul className={styles.executiveSummary}>
{versionSummary.map((change) => (
<li
key={change.name}
className={styles.versionChange}
>
<strong>{change.name}:</strong> {change.change}
</li>
))}
</ul>
)}
{showDescription && itemDescription && (
<div
className={styles.feedItemDescription}
dangerouslySetInnerHTML={{ __html: itemDescription }}
/>
)}
</div>
</a>
) : (
<div className={styles.feedItemContent}>
<h4 className={styles.feedItemTitle}>{displayTitle}</h4>
{itemDate && (
<time className={styles.feedItemDate}>
{formatLongDate(itemDate)}
</time>
)}
{versionSummary.length > 0 && (
<ul className={styles.executiveSummary}>
{versionSummary.map((change) => (
<li
key={change.name}
className={styles.versionChange}
>
<strong>{change.name}:</strong> {change.change}
</li>
))}
</ul>
)}
{showDescription && itemDescription && (
<div
className={styles.feedItemDescription}
dangerouslySetInnerHTML={{ __html: itemDescription }}
/>
)}
</div>
)}
</li>
);
})}
</ul>
</div>
);
} catch (error) {
console.error(`Error loading feed ${feedId}:`, error);
return (
<div className={styles.feedContainer}>
<h3 className={styles.feedTitle}>{title}</h3>
<p className={styles.error}>Error loading feed data</p>
</div>
);
}
};
export default FeedItems;