mirror of
https://github.com/Matewoo/pdf-writer.git
synced 2026-11-18 18:52:45 +01:00
add weeklyFeed scrolling + minor fixes
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
@@ -8,6 +7,9 @@
|
|||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: 'Fira Sans', sans-serif;
|
font-family: 'Fira Sans', sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@@ -15,7 +17,12 @@
|
|||||||
font-size: 50px;
|
font-size: 50px;
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
margin-top: 0;
|
margin: 0;
|
||||||
|
padding: 10px;
|
||||||
|
background: #ffffff;
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
@@ -52,24 +59,53 @@
|
|||||||
.side {
|
.side {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
margin-left:17px;
|
margin-left: 17px;
|
||||||
font-size: 23px;
|
font-size: 23px;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr {
|
hr {
|
||||||
border: 0;
|
border: 0;
|
||||||
border-top: 0.5px solid #707070;
|
border-top: 1px solid #2b2b2b;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
margin-left: 0;
|
margin-left: 0;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ticker-wrapper {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100vh;
|
||||||
|
padding-top: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ticker-content {
|
||||||
|
padding: 20px;
|
||||||
|
will-change: transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100vh;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Freuen Sie sich auf:</h1>
|
<script>
|
||||||
<h2></h2>
|
setInterval(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, 3600000);
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="../src/weeklyFeed.js"></script>
|
<script src="../src/weeklyFeed.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,40 +1,108 @@
|
|||||||
|
let currentWeek = new Date();
|
||||||
|
if (currentWeek.getDay() >= 5) { // 5 = Freitag
|
||||||
|
currentWeek.setDate(currentWeek.getDate() + 7);
|
||||||
|
}
|
||||||
|
currentWeek.setDate(currentWeek.getDate() - currentWeek.getDay() + 1);
|
||||||
|
|
||||||
|
let currentDayIndex = 0; // 0 = Monday, 4 = Friday
|
||||||
|
|
||||||
|
function getWeekNumber(date) {
|
||||||
|
const target = new Date(date.valueOf());
|
||||||
|
const dayNumber = (date.getDay() + 6) % 7;
|
||||||
|
target.setDate(target.getDate() - dayNumber + 3);
|
||||||
|
const firstThursday = target.valueOf();
|
||||||
|
target.setMonth(0, 1);
|
||||||
|
if (target.getDay() !== 4) {
|
||||||
|
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
|
||||||
|
}
|
||||||
|
return 1 + Math.ceil((firstThursday - target) / 604800000);
|
||||||
|
}
|
||||||
|
|
||||||
function loadWeek(week) {
|
function loadWeek(week) {
|
||||||
fetch(`/load-week?week=${encodeURIComponent(week)}`)
|
fetch(`/load-week?week=${encodeURIComponent(week)}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const sortedData = data.sort((a, b) => a.day_index - b.day_index);
|
// Default-Werte für leere Tage
|
||||||
|
const defaultData = {
|
||||||
|
date_title: 'WOCHENTAG',
|
||||||
|
meat_main: 'Eintrag fehlt',
|
||||||
|
meat_side: '',
|
||||||
|
veggi_main: 'Eintrag fehlt',
|
||||||
|
veggi_side: '',
|
||||||
|
halal: false,
|
||||||
|
day_index: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
let sortedData = [];
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
const dayData = data.find(item => item.day_index === i);
|
||||||
|
sortedData.push(dayData || { ...defaultData, day_index: i });
|
||||||
|
}
|
||||||
|
|
||||||
|
sortedData.sort((a, b) => a.day_index - b.day_index);
|
||||||
|
|
||||||
const container = document.querySelector('body');
|
const container = document.querySelector('body');
|
||||||
container.innerHTML = `
|
container.innerHTML = `
|
||||||
<h1>Freuen Sie sich auf:</h1>
|
<h1>Freuen Sie sich auf:</h1>
|
||||||
${sortedData.map(item => `
|
<div class="content">
|
||||||
<p class="category">— ${item.date_title} ${item.halal ? '<span class="halal">„HALAL"</span>' : ''}</p>
|
<div class="ticker-wrapper">
|
||||||
<p class="main">~ ${item.meat_main}</p>
|
<div class="ticker-content">
|
||||||
<p class="side">${item.meat_side}</p>
|
${sortedData.map(item => `
|
||||||
|
<div class="menu-item">
|
||||||
<p class="main">~ ${item.veggi_main}</p>
|
<p class="category">— ${item.date_title} ${item.halal ? '<span class="halal">„HALAL"</span>' : ''}</p>
|
||||||
<p class="side">${item.veggi_side}</p>
|
<p class="main">~ ${item.meat_main}</p>
|
||||||
<hr>
|
<p class="side">${item.meat_side}</p>
|
||||||
`).join('')}
|
<p class="main">~ ${item.veggi_main}</p>
|
||||||
`;
|
<p class="side">${item.veggi_side}</p>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
`).join('')}
|
||||||
|
</div>
|
||||||
|
<div class="ticker-content">
|
||||||
|
${sortedData.map(item => `
|
||||||
|
<div class="menu-item">
|
||||||
|
<p class="category">— ${item.date_title} ${item.halal ? '<span class="halal">„HALAL"</span>' : ''}</p>
|
||||||
|
<p class="main">~ ${item.meat_main}</p>
|
||||||
|
<p class="side">${item.meat_side}</p>
|
||||||
|
<p class="main">~ ${item.veggi_main}</p>
|
||||||
|
<p class="side">${item.veggi_side}</p>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
`).join('')}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
startScrolling();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error loading week:', error);
|
console.error('Error loading week:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current week number and year
|
function startScrolling() {
|
||||||
function getCurrentWeek() {
|
const tickerWrapper = document.querySelector('.ticker-wrapper');
|
||||||
const now = new Date();
|
const tickerContents = document.querySelectorAll('.ticker-content');
|
||||||
const start = new Date(now.getFullYear(), 0, 1);
|
|
||||||
const week = Math.ceil((((now - start) / 86400000) + start.getDay() + 1) / 7);
|
let currentPosition = 0;
|
||||||
return `KW${week} ${now.getFullYear()}`;
|
const contentHeight = tickerContents[0].offsetHeight;
|
||||||
|
|
||||||
|
function scroll() {
|
||||||
|
currentPosition -= 0.5;
|
||||||
|
|
||||||
|
if (Math.abs(currentPosition) >= contentHeight) {
|
||||||
|
currentPosition = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
tickerWrapper.style.transform = `translateY(${currentPosition}px)`;
|
||||||
|
requestAnimationFrame(scroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(scroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load current week's menu on page load
|
const weekNumber = getWeekNumber(currentWeek);
|
||||||
loadWeek(getCurrentWeek());
|
const year = currentWeek.getFullYear();
|
||||||
|
const week = `KW${weekNumber} ${year}`;
|
||||||
// Reload page every 15 seconds
|
console.log(week);
|
||||||
setInterval(() => {
|
loadWeek(week);
|
||||||
window.location.reload();
|
|
||||||
}, 15000);
|
|
||||||
Reference in New Issue
Block a user