update
This commit is contained in:
170
frontend/public/app.js
Normal file
170
frontend/public/app.js
Normal file
@@ -0,0 +1,170 @@
|
||||
// Load news on page load
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadNews();
|
||||
loadStats();
|
||||
});
|
||||
|
||||
async function loadNews() {
|
||||
const newsGrid = document.getElementById('newsGrid');
|
||||
newsGrid.innerHTML = '<div class="loading">Loading news...</div>';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/news');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.articles && data.articles.length > 0) {
|
||||
displayNews(data.articles);
|
||||
} else {
|
||||
newsGrid.innerHTML = '<div class="loading">No news available at the moment. Check back later!</div>';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading news:', error);
|
||||
newsGrid.innerHTML = '<div class="loading">Failed to load news. Please try again later.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function displayNews(articles) {
|
||||
const newsGrid = document.getElementById('newsGrid');
|
||||
newsGrid.innerHTML = '';
|
||||
|
||||
articles.forEach(article => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'news-card';
|
||||
card.onclick = () => window.open(article.link, '_blank');
|
||||
|
||||
card.innerHTML = `
|
||||
<div class="source">${article.source || 'Munich News'}</div>
|
||||
<h3>${article.title}</h3>
|
||||
<p>${article.summary || 'No summary available.'}</p>
|
||||
<a href="${article.link}" target="_blank" class="read-more" onclick="event.stopPropagation()">Read more →</a>
|
||||
`;
|
||||
|
||||
newsGrid.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
async function loadStats() {
|
||||
try {
|
||||
const response = await fetch('/api/stats');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.subscribers !== undefined) {
|
||||
document.getElementById('subscriberCount').textContent = data.subscribers.toLocaleString();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading stats:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function subscribe() {
|
||||
const emailInput = document.getElementById('emailInput');
|
||||
const subscribeBtn = document.getElementById('subscribeBtn');
|
||||
const formMessage = document.getElementById('formMessage');
|
||||
|
||||
const email = emailInput.value.trim();
|
||||
|
||||
if (!email || !email.includes('@')) {
|
||||
formMessage.textContent = 'Please enter a valid email address';
|
||||
formMessage.className = 'form-message error';
|
||||
return;
|
||||
}
|
||||
|
||||
subscribeBtn.disabled = true;
|
||||
subscribeBtn.textContent = 'Subscribing...';
|
||||
formMessage.textContent = '';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/subscribe', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ email: email })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
formMessage.textContent = data.message || 'Successfully subscribed! Check your email for confirmation.';
|
||||
formMessage.className = 'form-message success';
|
||||
emailInput.value = '';
|
||||
loadStats(); // Refresh stats
|
||||
} else {
|
||||
formMessage.textContent = data.error || 'Failed to subscribe. Please try again.';
|
||||
formMessage.className = 'form-message error';
|
||||
}
|
||||
} catch (error) {
|
||||
formMessage.textContent = 'Network error. Please try again later.';
|
||||
formMessage.className = 'form-message error';
|
||||
} finally {
|
||||
subscribeBtn.disabled = false;
|
||||
subscribeBtn.textContent = 'Subscribe Free';
|
||||
}
|
||||
}
|
||||
|
||||
// Allow Enter key to submit
|
||||
document.getElementById('emailInput').addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
subscribe();
|
||||
}
|
||||
});
|
||||
|
||||
function showUnsubscribe() {
|
||||
document.getElementById('unsubscribeModal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeUnsubscribe() {
|
||||
document.getElementById('unsubscribeModal').style.display = 'none';
|
||||
document.getElementById('unsubscribeEmail').value = '';
|
||||
document.getElementById('unsubscribeMessage').textContent = '';
|
||||
}
|
||||
|
||||
async function unsubscribe() {
|
||||
const emailInput = document.getElementById('unsubscribeEmail');
|
||||
const unsubscribeMessage = document.getElementById('unsubscribeMessage');
|
||||
|
||||
const email = emailInput.value.trim();
|
||||
|
||||
if (!email || !email.includes('@')) {
|
||||
unsubscribeMessage.textContent = 'Please enter a valid email address';
|
||||
unsubscribeMessage.className = 'form-message error';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/unsubscribe', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ email: email })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
unsubscribeMessage.textContent = data.message || 'Successfully unsubscribed.';
|
||||
unsubscribeMessage.className = 'form-message success';
|
||||
emailInput.value = '';
|
||||
setTimeout(() => {
|
||||
closeUnsubscribe();
|
||||
loadStats();
|
||||
}, 2000);
|
||||
} else {
|
||||
unsubscribeMessage.textContent = data.error || 'Failed to unsubscribe. Please try again.';
|
||||
unsubscribeMessage.className = 'form-message error';
|
||||
}
|
||||
} catch (error) {
|
||||
unsubscribeMessage.textContent = 'Network error. Please try again later.';
|
||||
unsubscribeMessage.className = 'form-message error';
|
||||
}
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
window.onclick = function(event) {
|
||||
const modal = document.getElementById('unsubscribeModal');
|
||||
if (event.target === modal) {
|
||||
closeUnsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
65
frontend/public/index.html
Normal file
65
frontend/public/index.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Munich News Daily - Your Daily Dose of Munich News</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header class="hero">
|
||||
<div class="hero-content">
|
||||
<h1>📰 Munich News Daily</h1>
|
||||
<p class="tagline">Get the latest Munich news delivered to your inbox every morning</p>
|
||||
<p class="description">Stay informed about what's happening in Munich with our curated daily newsletter. No fluff, just the news that matters.</p>
|
||||
|
||||
<div class="subscription-form" id="subscriptionForm">
|
||||
<input
|
||||
type="email"
|
||||
id="emailInput"
|
||||
placeholder="Enter your email address"
|
||||
required
|
||||
>
|
||||
<button id="subscribeBtn" onclick="subscribe()">Subscribe Free</button>
|
||||
<p class="form-message" id="formMessage"></p>
|
||||
</div>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stat-item">
|
||||
<span class="stat-number" id="subscriberCount">-</span>
|
||||
<span class="stat-label">Subscribers</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="news-section">
|
||||
<h2>Latest Munich News</h2>
|
||||
<div class="news-grid" id="newsGrid">
|
||||
<div class="loading">Loading news...</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<p>© 2024 Munich News Daily. Made with ❤️ for Munich.</p>
|
||||
<p><a href="#" onclick="showUnsubscribe()">Unsubscribe</a></p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<!-- Unsubscribe Modal -->
|
||||
<div class="modal" id="unsubscribeModal">
|
||||
<div class="modal-content">
|
||||
<span class="close" onclick="closeUnsubscribe()">×</span>
|
||||
<h2>Unsubscribe</h2>
|
||||
<p>Enter your email to unsubscribe from Munich News Daily:</p>
|
||||
<input type="email" id="unsubscribeEmail" placeholder="Enter your email">
|
||||
<button onclick="unsubscribe()">Unsubscribe</button>
|
||||
<p class="form-message" id="unsubscribeMessage"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
306
frontend/public/styles.css
Normal file
306
frontend/public/styles.css
Normal file
@@ -0,0 +1,306 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.hero {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.hero-content {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.hero h1 {
|
||||
font-size: 3.5rem;
|
||||
margin-bottom: 20px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.tagline {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 15px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 1.1rem;
|
||||
margin-bottom: 40px;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.subscription-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
max-width: 500px;
|
||||
margin: 0 auto 40px;
|
||||
}
|
||||
|
||||
.subscription-form input {
|
||||
padding: 15px 20px;
|
||||
font-size: 1rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
outline: none;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.subscription-form button {
|
||||
padding: 15px 30px;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
background: #ff6b6b;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.subscription-form button:hover {
|
||||
background: #ff5252;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.subscription-form button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.form-message {
|
||||
margin-top: 10px;
|
||||
font-size: 0.9rem;
|
||||
min-height: 20px;
|
||||
}
|
||||
|
||||
.form-message.success {
|
||||
color: #4caf50;
|
||||
}
|
||||
|
||||
.form-message.error {
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 40px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
display: block;
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.news-section {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 40px;
|
||||
margin: 40px 0;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.news-section h2 {
|
||||
font-size: 2rem;
|
||||
margin-bottom: 30px;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.news-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 25px;
|
||||
}
|
||||
|
||||
.news-card {
|
||||
background: #f8f9fa;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
transition: all 0.3s ease;
|
||||
border-left: 4px solid #667eea;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.news-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
|
||||
background: white;
|
||||
}
|
||||
|
||||
.news-card h3 {
|
||||
font-size: 1.2rem;
|
||||
margin-bottom: 10px;
|
||||
color: #333;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.news-card p {
|
||||
color: #666;
|
||||
font-size: 0.95rem;
|
||||
margin-bottom: 15px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.news-card .source {
|
||||
font-size: 0.85rem;
|
||||
color: #667eea;
|
||||
font-weight: 600;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.news-card .read-more {
|
||||
color: #667eea;
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.news-card .read-more:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #666;
|
||||
font-size: 1.1rem;
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
footer a {
|
||||
color: white;
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
footer a:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
/* Modal Styles */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(5px);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: white;
|
||||
margin: 15% auto;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.close {
|
||||
color: #aaa;
|
||||
float: right;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.modal-content h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.modal-content input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
margin: 15px 0;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.modal-content button {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
background: #ff6b6b;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.modal-content button:hover {
|
||||
background: #ff5252;
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
@media (max-width: 768px) {
|
||||
.hero h1 {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.tagline {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.news-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.stats {
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user