blob: ca2dddb9b4b8f2bb60acae980030e80fdf697ad6 (
plain) (
blame)
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
|
---
import { JSDOM } from 'jsdom';
const fetchContent = async (url) => {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch RSS feed: ${response.statusText}`);
}
return await response.text();
} catch (error) {
console.error(error);
return '<rss></rss>';
}
};
const rssData = await fetchContent(Astro.props.url);
// Parse the RSS data
const dom = new JSDOM(rssData);
const xmlDoc = dom.window.document;
const items = Array.from(xmlDoc.querySelectorAll("item")).slice(0, 7); // Only take the first 5 items
const title = xmlDoc.querySelector("title").textContent;
const link = xmlDoc.querySelector("link").textContent;
const description = xmlDoc.querySelector("description").textContent;
---
<style>
body {
font-family: Arial, sans-serif;
}
header {
padding: 20px;
margin-bottom: 20px;
border-radius: 8px;
}
ul {
list-style-type: none;
padding: 0;
}
li {
border-bottom: 1px solid #444;
padding: 10px 0;
transition: background-color 0.3s;
}
li:hover {
background-color: #3a3a3a;
}
a {
color: #f9a825;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
time {
color: #888;
font-size: 0.85em;
}
</style>
<ul>
{items.map(item => {
return (
<li key={item.querySelector("guid").textContent}>
<a href={item.querySelector("guid").textContent}>{item.querySelector("title").textContent}</a>
<p>{item.querySelector("description").textContent}</p>
<time>{item.querySelector("pubDate").textContent}</time>
</li>
);
})}
</ul>
|