generated from Stories-with-afzal/Stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlog rss
139 lines (119 loc) · 3.96 KB
/
Blog rss
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog Feed</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
#blog-feed {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #ffffff;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
#blog-feed div {
margin-bottom: 20px;
padding: 15px;
background-color: #f9f9f9;
border: 1px solid #ccc;
border-radius: 5px;
}
#blog-feed h3 {
margin: 0;
font-size: 1.5em;
color: #333;
}
#blog-feed p {
color: #666;
}
#blog-feed a {
text-decoration: none;
color: #007BFF;
}
#blog-feed a:hover {
text-decoration: underline;
color: #0056b3;
}
.pagination {
text-align: center;
margin-top: 20px;
}
.pagination button {
margin: 0 5px;
padding: 10px 15px;
border: none;
border-radius: 5px;
background-color: #007BFF;
color: white;
cursor: pointer;
}
.pagination button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
</style>
</head>
<body>
<div id="blog-feed"></div>
<div class="pagination">
<button id="prev-page" disabled>Previous</button>
<button id="next-page">Next</button>
</div>
<script>
const rssUrl = 'https://advafzal.blogspot.com/feeds/posts/default';
const itemsPerPage = 5;
let currentPage = 0;
let items = [];
async function fetchFeed() {
const response = await fetch(rssUrl);
const text = await response.text();
const parser = new DOMParser();
const xml = parser.parseFromString(text, 'text/xml');
items = Array.from(xml.querySelectorAll('item'));
displayItems();
}
function displayItems() {
const feedContainer = document.getElementById('blog-feed');
feedContainer.innerHTML = ''; // Clear previous items
const startIndex = currentPage * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const paginatedItems = items.slice(startIndex, endIndex);
paginatedItems.forEach(item => {
const title = item.querySelector('title').textContent;
const link = item.querySelector('link').textContent;
const description = item.querySelector('description').textContent;
const feedItem = document.createElement('div');
feedItem.innerHTML = `<h3><a href="${link}" target="_blank">${title}</a></h3><p>${description}</p>`;
feedContainer.appendChild(feedItem);
});
updatePaginationButtons();
}
function updatePaginationButtons() {
document.getElementById('prev-page').disabled = currentPage === 0;
document.getElementById('next-page').disabled = (currentPage + 1) * itemsPerPage >= items.length;
}
document.getElementById('prev-page').addEventListener('click', () => {
if (currentPage > 0) {
currentPage--;
displayItems();
}
});
document.getElementById('next-page').addEventListener('click', () => {
if ((currentPage + 1) * itemsPerPage < items.length) {
currentPage++;
displayItems();
}
});
fetchFeed();
</script>
</body>
</html>