Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update events share images #3849

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading