I'm trying to implement a "OnThisDay" Wikipedia style feature with Nextjs, showing an event that happened on that day. For this I have a function that looks like this:
const list = [{"dateOfDeath": "2000-01-01", "name": "X"},{"dateOfDeath": "2000-01-02", "name": "Y"]
const dateObj = new Date();
const currentDay =
('0' + (dateObj.getMonth() + 1)).slice(-2) +
'-' +
('0' + dateObj.getDate()).slice(-2);
export default function GetToday() {
return list.filter(
(person) => person.dateOfDeath.slice(5) === currentDay
);
}
I'm then getting this via getStaticProps:
export const getStaticProps: GetStaticProps = async () => {
const today = GetToday();
return {
props: {
today
},
revalidate: 10
};
};
This all works fine and well, however it seems that the Date object is created once at build time, so the page is stuck with whatever date the site was build on.
I purposfully set revalidate to 10s trying to solve this, which didn't work. I also tried using getServerSideProps instead but that didn't change anything either. I'm deploying the site with Docker, using pretty much the Docker template of the Nextjs repo.
Does someone know a way, that a new Date object is created at runtime?