fix: conditionally apply geo and location fields in calendar events

- Only include 'geo' object in the event attributes if valid latitude/longitude exists.
- Conditionally add 'location' field only when it is present on the event.
- Removed the 'noGeo' flag logic for conditional spreading, simplifying the map operation.
- Ensures clean event data without empty geo/location properties in the generated calendar file.
This commit is contained in:
kyuuseiryuu 2026-03-14 20:10:47 +09:00
parent 9657acea64
commit 4825f41337

View File

@ -57,16 +57,17 @@ const server = serve({
allEvents = allEvents.concat(...events.data);
}
const noGeo = !events.geo.lat && !events.geo.lng;
const geo = noGeo ? {} : { lat: events.geo.lat, lon: events.geo.lng };
const configs: ics.EventAttributes[] = allEvents?.filter(e => !e.isFinished)?.map(e => ({
...geo,
const geo = { lat: events.geo.lat, lon: events.geo.lng };
const configs: ics.EventAttributes[] = allEvents.filter(e => !e.isFinished).map(e => ({
...(noGeo ? {} : { geo }),
start: dayjs.tz(e.startDate, 'Asia/Tokyo').format('YYYY-MM-DD-HH-mm').split('-').map(v => Number(v)) as any,
duration: { hours: 6, minutes: 30 },
title: e.title,
// end: dayjs(event.startDate).add(6, 'h').add(30, 'minute').format('YYYY-MM-DD HH:mm'),
// description: 'Annual 10-kilometer run in Boulder, Colorado',
location: e.location,
// url: e.url,
...(e.location ? { location: e.location } : {}),
// geo: { lat: events.location.lat, lon: events.location.lng },
alarms: [
{ action: 'display', summary: e.title, description: '距离比赛开始还有 2 小时', trigger: { before: true, hours: 2 } },