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 kitchenImage from '@/images/photos/kitchen.jpg'
|
||||||
import { type BlogPostWithSlug, getAllBlogPosts } from '@/lib/articles'
|
import { type BlogPostWithSlug, getAllBlogPosts } from '@/lib/articles'
|
||||||
import { formatDate } from '@/lib/formatDate'
|
import { formatDate } from '@/lib/formatDate'
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
|
||||||
function LinkButton({
|
function LinkButton({
|
||||||
href,
|
href,
|
||||||
@ -100,21 +101,36 @@ function MeetingListItem({ meeting }: { meeting: Meeting }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Events() {
|
async function Events() {
|
||||||
let events: Array<Meeting> = [
|
const now = new Date();
|
||||||
{
|
const nowYear = now.getFullYear();
|
||||||
title: 'January Potluck',
|
const nowMonth = now.getMonth() + 1;
|
||||||
date: '2024-01-20',
|
const nowDay = now.getDate();
|
||||||
startTime: '6:00pm',
|
|
||||||
},
|
const file = await fs.readFile(process.cwd() + '/src/app/upcoming-events.json', 'utf8');
|
||||||
{
|
const allEvents: Array<Meeting> = JSON.parse(file);
|
||||||
title: 'February Potluck',
|
|
||||||
date: '2024-02-17',
|
// Remove any events in the past.
|
||||||
startTime: '6:00pm',
|
const events = allEvents.filter((e) => {
|
||||||
// endTime: '8:00pm',
|
const [year, month, day] = e.date.split('-');
|
||||||
// notes: 'Bring your own chair.'
|
|
||||||
},
|
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 (
|
return (
|
||||||
<div className="rounded-2xl border border-zinc-100 p-6 dark:border-zinc-700/40">
|
<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