Spaces:
Running
Running
Commit
·
180b13e
1
Parent(s):
7a70225
Create script.js
Browse files
script.js
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// script.js
|
2 |
+
|
3 |
+
// This script will fetch the summarized data from the backend and populate the HTML
|
4 |
+
|
5 |
+
document.addEventListener('DOMContentLoaded', function() {
|
6 |
+
fetchSummaries();
|
7 |
+
});
|
8 |
+
|
9 |
+
function fetchSummaries() {
|
10 |
+
fetch('/api/summaries')
|
11 |
+
.then(response => response.json())
|
12 |
+
.then(data => {
|
13 |
+
populateNewsletter(data);
|
14 |
+
})
|
15 |
+
.catch(error => console.error('Error:', error));
|
16 |
+
}
|
17 |
+
|
18 |
+
function populateNewsletter(summaries) {
|
19 |
+
const newsletterSection = document.getElementById('newsletter');
|
20 |
+
|
21 |
+
summaries.forEach(summary => {
|
22 |
+
const article = document.createElement('article');
|
23 |
+
const h2 = document.createElement('h2');
|
24 |
+
const p = document.createElement('p');
|
25 |
+
|
26 |
+
h2.textContent = summary.title;
|
27 |
+
p.textContent = summary.content;
|
28 |
+
|
29 |
+
article.appendChild(h2);
|
30 |
+
article.appendChild(p);
|
31 |
+
|
32 |
+
newsletterSection.appendChild(article);
|
33 |
+
});
|
34 |
+
}
|