mirror of
https://gitlab.com/OpenAlt/OpenAltRO/openalt_ro.git
synced 2026-11-23 15:19:15 +00:00
Implement announcement status and make events upcoming or planned accordingly, fill in the Luma links
This commit is contained in:
parent
e51d53994a
commit
bda956da23
9 changed files with 49 additions and 20 deletions
|
|
@ -1,5 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
// Same query Hexo uses for its default `posts` local. We start from this on
|
||||
// every run instead of hexo.locals.get('posts'), because we overwrite that
|
||||
// local below; under `hexo server` the next regeneration would otherwise start
|
||||
// from the already-filtered list and lose the hidden events for good.
|
||||
function basePosts() {
|
||||
const query = {};
|
||||
if (!hexo.config.future) query.date = { $lte: Date.now() };
|
||||
if (!hexo._showDrafts()) query.published = true;
|
||||
return hexo.model('Post').find(query);
|
||||
}
|
||||
|
||||
hexo.extend.filter.register('before_generate', function () {
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
|
@ -9,7 +20,8 @@ hexo.extend.filter.register('before_generate', function () {
|
|||
post.tags.data.some(function (t) { return t.name === 'Events'; });
|
||||
}
|
||||
|
||||
const allPosts = hexo.locals.get('posts').toArray();
|
||||
const posts = basePosts();
|
||||
const allPosts = posts.toArray();
|
||||
|
||||
const eventPosts = allPosts
|
||||
.filter(isEventPost)
|
||||
|
|
@ -22,30 +34,38 @@ hexo.extend.filter.register('before_generate', function () {
|
|||
return p.date.valueOf() >= today.getTime();
|
||||
});
|
||||
|
||||
hexo.locals.set('nextEvent', futureEvents[0] || false);
|
||||
// `event.announced: false` marks a planned date that isn't confirmed yet.
|
||||
// Such events never become the homepage "Next Meetup".
|
||||
function isAnnounced(p) {
|
||||
return !(p.event && p.event.announced === false);
|
||||
}
|
||||
|
||||
const nextEvent = futureEvents.find(isAnnounced) || false;
|
||||
hexo.locals.set('nextEvent', nextEvent);
|
||||
// Most recent past event that actually has a video (skips TBD / missing).
|
||||
const pastWithVideo = pastEvents.filter(function (p) {
|
||||
return p.event && p.event.video && p.event.video !== 'TBD';
|
||||
});
|
||||
hexo.locals.set('lastEvent', pastWithVideo[pastWithVideo.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; }));
|
||||
// Far-future events (all future except the nearest one and the next
|
||||
// announced one) are excluded from site.posts so they don't appear in
|
||||
// archives or RSS.
|
||||
const hiddenIds = new Set(futureEvents
|
||||
.filter(function (p) { return p !== futureEvents[0] && p !== nextEvent; })
|
||||
.map(function (p) { return p._id; }));
|
||||
|
||||
// Every event (including hidden far-future ones) for the /events/ timeline.
|
||||
// `hasPage` is false for hidden events, since no page is generated for them.
|
||||
hexo.locals.set('allEvents', eventPosts.map(function (p) {
|
||||
let state = 'upcoming';
|
||||
if (p.date.valueOf() < today.getTime()) state = 'past';
|
||||
else if (p === futureEvents[0]) state = 'next';
|
||||
else if (p === nextEvent) state = 'next';
|
||||
else if (!isAnnounced(p)) state = 'planned';
|
||||
return { post: p, state: state, hasPage: !hiddenIds.has(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);
|
||||
}
|
||||
hexo.locals.set('posts', posts.filter(function (p) {
|
||||
return !hiddenIds.has(p._id);
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue