Enhance date rendering in schedule script to include contextual labels for today and tomorrow. Updated renderDay function to accept flags for isToday and isTomorrow, modifying the title accordingly. Also, added versioning to the script source in index.html for cache management.
This commit is contained in:
parent
60409362c7
commit
370519a812
2 changed files with 23 additions and 5 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/script.js"></script>
|
<script src="/static/script.js?v=2"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,22 @@ function getTomorrowInLondon() {
|
||||||
return date.toISOString().split('T')[0];
|
return date.toISOString().split('T')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderDay(container, titleEl, dateStr, items) {
|
function renderDay(container, titleEl, dateStr, items, isToday = false, isTomorrow = false) {
|
||||||
titleEl.textContent = formatDate(dateStr);
|
let titleText = formatDate(dateStr);
|
||||||
|
if (isToday) {
|
||||||
|
// Преобразуем "Вторник, 30 декабря" в "Сегодня вторник, 30 декабря"
|
||||||
|
const parts = titleText.split(', ');
|
||||||
|
if (parts.length === 2) {
|
||||||
|
titleText = `Сегодня ${parts[0].toLowerCase()}, ${parts[1]}`;
|
||||||
|
}
|
||||||
|
} else if (isTomorrow) {
|
||||||
|
// Преобразуем "Среда, 31 декабря" в "Завтра среда, 31 декабря"
|
||||||
|
const parts = titleText.split(', ');
|
||||||
|
if (parts.length === 2) {
|
||||||
|
titleText = `Завтра ${parts[0].toLowerCase()}, ${parts[1]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
titleEl.textContent = titleText;
|
||||||
|
|
||||||
const tasks = items.filter(item => item.kind === 'task');
|
const tasks = items.filter(item => item.kind === 'task');
|
||||||
const events = items.filter(item => item.kind === 'event');
|
const events = items.filter(item => item.kind === 'event');
|
||||||
|
|
@ -101,14 +115,18 @@ async function loadSchedule() {
|
||||||
document.getElementById('today-content'),
|
document.getElementById('today-content'),
|
||||||
document.getElementById('today-title'),
|
document.getElementById('today-title'),
|
||||||
today,
|
today,
|
||||||
todayItems
|
todayItems,
|
||||||
|
true, // isToday
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
renderDay(
|
renderDay(
|
||||||
document.getElementById('tomorrow-content'),
|
document.getElementById('tomorrow-content'),
|
||||||
document.getElementById('tomorrow-title'),
|
document.getElementById('tomorrow-title'),
|
||||||
tomorrow,
|
tomorrow,
|
||||||
tomorrowItems
|
tomorrowItems,
|
||||||
|
false,
|
||||||
|
true // isTomorrow
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading schedule:', error);
|
console.error('Error loading schedule:', error);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue