Skip to content

Commit 5ceeba8

Browse files
committed
Fix last update: sort chapters by ID instead of date
1 parent 06589f0 commit 5ceeba8

2 files changed

Lines changed: 50 additions & 16 deletions

File tree

assets/js/admin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
title: chapterTitle,
302302
language: lang,
303303
type: lang === 'ru' ? 'translation' : 'original',
304-
date_published: new Date().toISOString().slice(0, 10),
304+
date_published: new Date().toISOString(),
305305
content: content
306306
};
307307

@@ -382,10 +382,13 @@
382382

383383
var lastDate = null;
384384
chapters.forEach(function(c) {
385-
if (!lastDate || c.date_published > lastDate) {
386-
lastDate = c.date_published;
385+
var dateStr = c.date_published || '';
386+
if (!lastDate || dateStr > lastDate) {
387+
lastDate = dateStr;
387388
}
388389
});
390+
// Для отображения только даты:
391+
var displayDate = lastDate ? lastDate.slice(0, 10) : null;
389392

390393
supabase
391394
.from('titles')

index.html

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@
7070
(function() {
7171
document.getElementById('footer-year').textContent = new Date().getFullYear();
7272

73-
// Ждем, пока App станет доступен
7473
function waitForApp(callback) {
7574
if (window.App && window.App.loadLibrary) {
7675
callback();
7776
} else {
78-
console.log('Waiting for App to load...');
7977
setTimeout(function() { waitForApp(callback); }, 100);
8078
}
8179
}
@@ -87,21 +85,54 @@
8785
if (t) { t.href = data.site.telegram || '#'; }
8886
var ft = document.getElementById('footer-telegram');
8987
if (ft) { ft.href = data.site.telegram || '#'; }
90-
var last = document.getElementById('hero-last');
91-
if (last && data.titles && data.titles.length) {
92-
var lastTitle = data.titles[0];
93-
var lastCh = lastTitle.chapters && lastTitle.chapters.length
94-
? lastTitle.chapters.slice().sort(function(a,b) { return (b.datePublished || '').localeCompare(a.datePublished || ''); })[0]
95-
: null;
96-
if (lastCh) {
97-
last.textContent = 'Последнее обновление: ' + (lastTitle.title || lastTitle.titleEn) + ' — гл. ' + (lastCh.number || lastCh.id);
98-
} else {
99-
last.textContent = 'Последнее обновление: ' + (data.site.lastUpdated || '');
88+
}
89+
90+
var lastEl = document.getElementById('hero-last');
91+
if (lastEl && data && data.titles) {
92+
var allChapters = [];
93+
94+
// Собираем все главы со всех тайтлов
95+
data.titles.forEach(function(title) {
96+
if (title.chapters && title.chapters.length) {
97+
title.chapters.forEach(function(ch) {
98+
allChapters.push({
99+
title: title.title || title.titleEn || 'Unknown',
100+
titleId: title.id,
101+
chapter: ch
102+
});
103+
});
104+
}
105+
});
106+
107+
if (allChapters.length > 0) {
108+
// Сортируем по ID (самые новые главы имеют больший ID)
109+
allChapters.sort(function(a, b) {
110+
return (b.chapter.id || 0) - (a.chapter.id || 0);
111+
});
112+
113+
var latest = allChapters[0];
114+
var titleName = latest.title;
115+
var chapterNum = latest.chapter.number != null ? latest.chapter.number : latest.chapter.id;
116+
var pubDate = latest.chapter.datePublished || '';
117+
118+
// Форматируем дату для отображения
119+
function formatDate(dateStr) {
120+
if (!dateStr) return '';
121+
var date = new Date(dateStr);
122+
return date.toLocaleDateString('ru-RU', {
123+
day: '2-digit',
124+
month: '2-digit',
125+
year: 'numeric'
126+
});
100127
}
128+
129+
var displayDate = formatDate(pubDate);
130+
lastEl.textContent = 'Последнее обновление: ' + titleName + ' — гл. ' + chapterNum + ' (' + displayDate + ')';
101131
} else {
102-
last.textContent = data.site.lastUpdated ? 'Обновлено: ' + data.site.lastUpdated : '';
132+
lastEl.textContent = data.site.lastUpdated ? 'Обновлено: ' + data.site.lastUpdated : '';
103133
}
104134
}
135+
105136
App.renderHome(document.getElementById('titles-grid'), data);
106137
}).catch(function(error) {
107138
console.error('Error loading data:', error);

0 commit comments

Comments
 (0)