Skip to content

Commit

Permalink
update events share images (#3849)
Browse files Browse the repository at this point in the history
  • Loading branch information
reigj1 authored Dec 4, 2024
1 parent 50e4c4b commit ed40025
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plugins/airtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,21 @@ async function fetchAirtableRecords({ apiKey, baseId, tableName, viewId }) {
}

async function processEventsData(records) {
const endDateCutoff = new Date(Date.now() - 6 * 30 * 24 * 60 * 60 * 1000)
.toISOString()
.split("T")[0];

const today = new Date().toISOString().split("T")[0];

records = await Promise.all(
records.map(async (record) => {
const parsedRecord = parseAirtableData(record);

let imageUrl = await fetchShareImage(parsedRecord.eventLink);
// Only fetch share image for current/future events
let imageUrl = null;
if (parsedRecord.endDate >= today) {
imageUrl = await fetchShareImage(parsedRecord.eventLink);
}

// If no share image is found, use a default image
if (!imageUrl) {
Expand All @@ -171,10 +181,6 @@ async function processEventsData(records) {
})
);

const endDatecutoff = new Date(Date.now() - 6 * 30 * 24 * 60 * 60 * 1000)
.toISOString()
.split("T")[0];

records = records.filter((rec) => {
if (!rec.startDate || new Date(rec.startDate) == "Invalid Date") {
logger.warn("Invalid event, no start date: " + rec.eventName);
Expand All @@ -186,7 +192,7 @@ async function processEventsData(records) {
return false;
}

if (rec.endDate < endDatecutoff) {
if (rec.endDate < endDateCutoff) {
// old event
return false;
}
Expand Down

0 comments on commit ed40025

Please sign in to comment.