Spaces:
Running
Running
| // script.js | |
| // This script will fetch the summarized data from the backend and populate the HTML | |
| document.addEventListener('DOMContentLoaded', function() { | |
| fetchSummaries(); | |
| }); | |
| function fetchSummaries() { | |
| fetch('/api/summaries') | |
| .then(response => response.json()) | |
| .then(data => { | |
| populateNewsletter(data); | |
| }) | |
| .catch(error => console.error('Error:', error)); | |
| } | |
| function populateNewsletter(summaries) { | |
| const newsletterSection = document.getElementById('newsletter'); | |
| summaries.forEach(summary => { | |
| const article = document.createElement('article'); | |
| const h2 = document.createElement('h2'); | |
| const p = document.createElement('p'); | |
| h2.textContent = summary.title; | |
| p.textContent = summary.content; | |
| article.appendChild(h2); | |
| article.appendChild(p); | |
| newsletterSection.appendChild(article); | |
| }); | |
| } |