diff --git a/src/app/page.tsx b/src/app/page.tsx index feb2318..1c1aecf 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -12,6 +12,7 @@ import interorEmptyImage from '@/images/photos/interior-empty.jpg' import kitchenImage from '@/images/photos/kitchen.jpg' import { type BlogPostWithSlug, getAllBlogPosts } from '@/lib/articles' import { formatDate } from '@/lib/formatDate' +import { promises as fs } from 'fs'; function LinkButton({ href, @@ -100,21 +101,36 @@ function MeetingListItem({ meeting }: { meeting: Meeting }) { ) } -function Events() { - let events: Array = [ - { - title: 'January Potluck', - date: '2024-01-20', - startTime: '6:00pm', - }, - { - title: 'February Potluck', - date: '2024-02-17', - startTime: '6:00pm', - // endTime: '8:00pm', - // notes: 'Bring your own chair.' - }, - ] +async function Events() { + const now = new Date(); + const nowYear = now.getFullYear(); + const nowMonth = now.getMonth() + 1; + const nowDay = now.getDate(); + + const file = await fs.readFile(process.cwd() + '/src/app/upcoming-events.json', 'utf8'); + const allEvents: Array = JSON.parse(file); + + // Remove any events in the past. + const events = allEvents.filter((e) => { + const [year, month, day] = e.date.split('-'); + + const parsedYear = parseInt(year) + if (parsedYear > nowYear) { + return true + } else if (parsedYear < nowYear) { + return false + } + + const parsedMonth = parseInt(month) + if (parsedMonth > nowMonth) { + return true + } else if (parsedMonth < nowMonth) { + return false + } + + const parsedDay = parseInt(day) + return parsedDay >= nowDay + }); return (
diff --git a/src/app/upcoming-events.json b/src/app/upcoming-events.json new file mode 100644 index 0000000..d0095bd --- /dev/null +++ b/src/app/upcoming-events.json @@ -0,0 +1,24 @@ +[ + { + "title": "January Potluck", + "date": "2024-01-20", + "startTime": "6:00pm" + }, + { + "title": "February Potluck", + "date": "2024-02-17", + "startTime": "6:00pm", + "notes": "With historic West Sound slide show." + }, + { + "title": "Town Hall Meeting", + "date": "2024-03-06", + "startTime": "6:00pm", + "endTime": "8:00pm" + }, + { + "title": "March Potluck", + "date": "2024-03-16", + "startTime": "6:00pm" + } +] \ No newline at end of file