Filter out old events for smaller page payloads
This commit is contained in:
1 parent
d008c75a93
commit
af1bc9d332
4 files changed
+61
-11
No files matched your search
@@ -2,10 +2,17 @@ const _ = require('lodash')
|
||||
const path = require('path')
|
||||
const { createFilePath } = require('gatsby-source-filesystem')
|
||||
const { paginate } = require('gatsby-awesome-pagination')
|
||||
const moment = require('moment')
|
||||
|
||||
const getOnlyPublished = edges =>
|
||||
_.filter(edges, ({ node }) => node.status === 'publish')
|
||||
|
||||
// Used to filter out older events from queries
|
||||
const eventsNotBefore = moment()
|
||||
.startOf('day')
|
||||
.subtract(1, 'days')
|
||||
.toISOString()
|
||||
|
||||
exports.createPages = ({ actions, graphql }) => {
|
||||
const { createPage } = actions
|
||||
|
||||
@@ -275,6 +282,7 @@ exports.createPages = ({ actions, graphql }) => {
|
||||
slug: eventOrganizer.slug,
|
||||
description: eventOrganizer.description,
|
||||
association: eventOrganizer.association,
|
||||
after: eventsNotBefore,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -440,3 +448,22 @@ exports.onCreateNode = ({ node, actions, getNode }) => {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exports.onCreatePage = ({ page, actions }) => {
|
||||
const { createPage, deletePage } = actions
|
||||
|
||||
// We need to add context to a few pages
|
||||
const pagesWithContext = ['/', '/program/']
|
||||
if (!pagesWithContext.includes(page.path)) {
|
||||
return
|
||||
}
|
||||
|
||||
deletePage(page)
|
||||
createPage({
|
||||
...page,
|
||||
context: {
|
||||
...page.context,
|
||||
after: eventsNotBefore,
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user