-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
71 lines (66 loc) · 2.56 KB
/
index2.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>In-Shorts Like App</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.3/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css">
<style>
.swiper-container {
height: 100vh;
}
.swiper-slide {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
</style>
</head>
<body class="bg-gray-100">
<div class="swiper-container">
<div class="swiper-wrapper" id="news-wrapper">
<!-- News cards will be dynamically injected here -->
</div>
</div>
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<script>
// Function to fetch news from the backend API
async function fetchNews() {
try {
const response = await fetch('http://127.0.0.1:5002/summary');
const data = await response.json();
populateNews(data.articles);
} catch (error) {
console.error('Error fetching news:', error);
}
}
// Function to populate the Swiper with news articles
function populateNews(articles) {
const newsWrapper = document.getElementById('news-wrapper');
newsWrapper.innerHTML = ''; // Clear existing content
articles.forEach(article => {
const newsCard = document.createElement('div');
newsCard.className = 'swiper-slide bg-white p-4 rounded-lg shadow-lg';
newsCard.innerHTML = `
<img src="${article.thumbnail_url || 'default-image.jpg'}" alt="${article.title}" class="w-full h-64 object-cover rounded-t-lg">
<h2 class="text-xl font-bold mt-4">${article.title}</h2>
<p class="mt-2 text-gray-600">${article.summary || ''}</p>
`;
newsWrapper.appendChild(newsCard);
});
// Initialize Swiper after dynamically populating the content
new Swiper('.swiper-container', {
direction: 'vertical',
pagination: {
el: '.swiper-pagination',
clickable: true,
},
});
}
// Fetch news when the page loads
window.onload = fetchNews;
</script>
</body>
</html>