330 lines
8.8 KiB
HTML
330 lines
8.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>News</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
|
|
background-attachment: fixed;
|
|
color: white;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
padding: 30px 20px;
|
|
}
|
|
|
|
/* Extra-wide custom high-contrast scrollbar for senior usability */
|
|
::-webkit-scrollbar {
|
|
width: 18px;
|
|
}
|
|
::-webkit-scrollbar-track {
|
|
background: rgba(0, 0, 0, 0.3);
|
|
}
|
|
::-webkit-scrollbar-thumb {
|
|
background: rgba(255, 255, 255, 0.3);
|
|
border: 4px solid transparent;
|
|
border-radius: 9px;
|
|
background-clip: padding-box;
|
|
}
|
|
::-webkit-scrollbar-thumb:hover {
|
|
background: rgba(255, 255, 255, 0.5);
|
|
border: 4px solid transparent;
|
|
border-radius: 9px;
|
|
background-clip: padding-box;
|
|
}
|
|
|
|
/* Frosted glass container */
|
|
.container {
|
|
background: rgba(0, 0, 0, 0.4);
|
|
backdrop-filter: blur(16px);
|
|
-webkit-backdrop-filter: blur(16px);
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
border-radius: 36px;
|
|
padding: 40px 30px;
|
|
width: 100%;
|
|
max-width: 1000px;
|
|
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
|
|
}
|
|
|
|
header {
|
|
text-align: center;
|
|
margin-bottom: 40px;
|
|
}
|
|
|
|
header h1 {
|
|
font-size: 48px;
|
|
font-weight: bold;
|
|
color: #fff;
|
|
letter-spacing: 1px;
|
|
text-shadow: 0 4px 10px rgba(0,0,0,0.3);
|
|
}
|
|
|
|
header p {
|
|
font-size: 20px;
|
|
color: #ffd700;
|
|
margin-top: 8px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
#loading-box {
|
|
text-align: center;
|
|
font-size: 26px;
|
|
padding: 60px 0;
|
|
color: #e2e8f0;
|
|
}
|
|
|
|
.category-title {
|
|
font-size: 32px;
|
|
font-weight: bold;
|
|
color: #38bdf8;
|
|
margin: 40px 0 20px 0;
|
|
border-bottom: 3px solid rgba(56, 189, 248, 0.3);
|
|
padding-bottom: 10px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
/* Accordion stories list */
|
|
.stories-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 16px;
|
|
}
|
|
|
|
.story-card {
|
|
background: rgba(255, 255, 255, 0.05);
|
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
border-radius: 20px;
|
|
overflow: hidden;
|
|
transition: background 0.2s, transform 0.15s;
|
|
}
|
|
|
|
.story-card:hover {
|
|
background: rgba(255, 255, 255, 0.09);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
/* Large tap target for header */
|
|
.story-header {
|
|
padding: 24px 28px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
gap: 20px;
|
|
user-select: none;
|
|
}
|
|
|
|
.story-headline {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
line-height: 1.35;
|
|
color: #fff;
|
|
}
|
|
|
|
.story-chevron {
|
|
font-size: 28px;
|
|
color: #94a3b8;
|
|
transition: transform 0.2s;
|
|
}
|
|
|
|
.story-card.open .story-chevron {
|
|
transform: rotate(90deg);
|
|
color: #38bdf8;
|
|
}
|
|
|
|
/* Smooth accordion drawer */
|
|
.story-body {
|
|
max-height: 0;
|
|
overflow: hidden;
|
|
transition: max-height 0.35s ease-in-out;
|
|
background: rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.story-card.open .story-body {
|
|
/* Transition is controlled dynamically via JS max-height for perfect animations */
|
|
}
|
|
|
|
.story-content {
|
|
padding: 24px 28px;
|
|
border-top: 1px solid rgba(255, 255, 255, 0.05);
|
|
}
|
|
|
|
.story-summary {
|
|
font-size: 22px;
|
|
line-height: 1.6;
|
|
color: #f1f5f9;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.story-meta {
|
|
font-size: 16px;
|
|
color: #94a3b8;
|
|
font-weight: bold;
|
|
}
|
|
|
|
/* Giant Home Button */
|
|
.footer-nav {
|
|
text-align: center;
|
|
margin-top: 50px;
|
|
}
|
|
|
|
.home-btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: linear-gradient(135deg, #10b981, #059669);
|
|
color: white;
|
|
text-decoration: none;
|
|
padding: 22px 55px;
|
|
font-size: 28px;
|
|
font-weight: bold;
|
|
border-radius: 22px;
|
|
box-shadow: 0 8px 24px rgba(16, 185, 129, 0.35);
|
|
cursor: pointer;
|
|
border: none;
|
|
transition: transform 0.1s, box-shadow 0.1s;
|
|
}
|
|
|
|
.home-btn:hover {
|
|
transform: translateY(-3px);
|
|
box-shadow: 0 12px 30px rgba(16, 185, 129, 0.5);
|
|
}
|
|
|
|
.home-btn:active {
|
|
transform: translateY(0px);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<header>
|
|
<h1>📰 Daily Newspaper</h1>
|
|
<p id="newspaper-date">Today's Edition</p>
|
|
</header>
|
|
|
|
<div id="loading-box">🗞️ Delivery in progress... Please wait.</div>
|
|
|
|
<div id="news-content" style="display: none;">
|
|
<!-- World News Section -->
|
|
<div class="category-title">🌐 World News</div>
|
|
<div class="stories-list" id="world-news-list"></div>
|
|
|
|
<!-- National News Section -->
|
|
<div class="category-title">🇺🇸 National News</div>
|
|
<div class="stories-list" id="national-news-list"></div>
|
|
</div>
|
|
|
|
<div class="footer-nav">
|
|
<a href="index.html" class="home-btn">⌂ Go Home</a>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Format publication dates cleanly
|
|
function formatToday() {
|
|
const now = new Date();
|
|
return now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
|
|
}
|
|
|
|
async function loadNews() {
|
|
document.getElementById('newspaper-date').textContent = formatToday();
|
|
|
|
try {
|
|
const resp = await fetch("news-data.json");
|
|
const data = await resp.json();
|
|
|
|
renderCategory("World News", data["World News"], "world-news-list");
|
|
renderCategory("National News", data["National News"], "national-news-list");
|
|
|
|
document.getElementById('loading-box').style.display = 'none';
|
|
document.getElementById('news-content').style.display = 'block';
|
|
} catch (e) {
|
|
document.getElementById('loading-box').textContent = "⚠️ Preparing newspaper... Please wait a moment.";
|
|
}
|
|
}
|
|
|
|
function renderCategory(catName, stories, containerId) {
|
|
const box = document.getElementById(containerId);
|
|
box.innerHTML = ""; // Clear loader
|
|
|
|
if (!stories || stories.length === 0) {
|
|
box.innerHTML = `<div style="padding: 20px; font-size: 20px; color: #94a3b8; text-align: center;">No stories available.</div>`;
|
|
return;
|
|
}
|
|
|
|
stories.forEach((story, idx) => {
|
|
const card = document.createElement('div');
|
|
card.className = 'story-card';
|
|
|
|
// Wrap each scraped paragraph in a comfortable <p> block for readability
|
|
const formattedSummary = story.summary
|
|
.split('\n\n')
|
|
.map(para => `<p style="margin-bottom:18px;">${para}</p>`)
|
|
.join('');
|
|
|
|
card.innerHTML = `
|
|
<div class="story-header" onclick="toggleStory(this)">
|
|
<div class="story-headline">${story.title}</div>
|
|
<div class="story-chevron">▸</div>
|
|
</div>
|
|
<div class="story-body">
|
|
<div class="story-content">
|
|
${story.image ? `<img src="${story.image}" style="width:100%; max-height:450px; object-fit:cover; border-radius:16px; margin-bottom:24px; box-shadow: 0 4px 15px rgba(0,0,0,0.35);" onerror="this.style.display='none'">` : ''}
|
|
<div class="story-summary">${formattedSummary}</div>
|
|
<div class="story-meta">📰 Source: ${story.source || 'Daily Digest'} | ⌚ Published: ${story.date || 'Recent'}</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
box.appendChild(card);
|
|
});
|
|
}
|
|
|
|
// Interactive in-place accordion expansion with scroll-to-focus
|
|
function toggleStory(headerElement) {
|
|
const card = headerElement.parentElement;
|
|
const body = card.querySelector('.story-body');
|
|
const isOpen = card.classList.contains('open');
|
|
|
|
// Close ALL other story cards globally across all categories
|
|
const allCards = document.querySelectorAll('.story-card');
|
|
allCards.forEach(c => {
|
|
if (c !== card) {
|
|
c.classList.remove('open');
|
|
const b = c.querySelector('.story-body');
|
|
if (b) {
|
|
b.style.maxHeight = '0px';
|
|
}
|
|
}
|
|
});
|
|
|
|
if (!isOpen) {
|
|
card.classList.add('open');
|
|
if (body) {
|
|
body.style.maxHeight = body.scrollHeight + 'px';
|
|
}
|
|
// Smoothly scroll the newly opened story card to the top of the viewport
|
|
setTimeout(() => {
|
|
card.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
}, 100);
|
|
} else {
|
|
card.classList.remove('open');
|
|
if (body) {
|
|
body.style.maxHeight = '0px';
|
|
}
|
|
}
|
|
}
|
|
|
|
window.onload = loadNews;
|
|
</script>
|
|
</body>
|
|
</html>
|