Load upcoming events from json file
This commit is contained in:
parent
c263bc4573
commit
18f711444f
@ -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<Meeting> = [
|
||||
{
|
||||
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<Meeting> = 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 (
|
||||
<div className="rounded-2xl border border-zinc-100 p-6 dark:border-zinc-700/40">
|
||||
|
24
src/app/upcoming-events.json
Normal file
24
src/app/upcoming-events.json
Normal file
@ -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"
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user