Improved homepage, added newsletter self-subscription

This commit is contained in:
Bashy 2026-06-11 15:45:56 +03:00
parent e820431d0c
commit 4ac6e74cdc
9 changed files with 348 additions and 36 deletions

38
scripts/event_filter.js Normal file
View file

@ -0,0 +1,38 @@
'use strict';
hexo.extend.filter.register('before_generate', function () {
const today = new Date();
today.setHours(0, 0, 0, 0);
function isEventPost(post) {
return post.tags && post.tags.data &&
post.tags.data.some(function (t) { return t.name === 'Events'; });
}
const allPosts = hexo.locals.get('posts').toArray();
const eventPosts = allPosts
.filter(isEventPost)
.sort(function (a, b) { return a.date.valueOf() - b.date.valueOf(); });
const pastEvents = eventPosts.filter(function (p) {
return p.date.valueOf() < today.getTime();
});
const futureEvents = eventPosts.filter(function (p) {
return p.date.valueOf() >= today.getTime();
});
hexo.locals.set('nextEvent', futureEvents[0] || false);
hexo.locals.set('lastEvent', pastEvents[pastEvents.length - 1] || false);
// Far-future events (all future except the nearest one) are excluded from
// site.posts so they don't appear in archives or RSS.
const hiddenIds = new Set(futureEvents.slice(1).map(function (p) { return p._id; }));
if (hiddenIds.size > 0) {
const filtered = hexo.locals.get('posts').filter(function (p) {
return !hiddenIds.has(p._id);
});
hexo.locals.set('posts', filtered);
}
});