From 94528b129f8f70d8ec85a50c67829a0b20245848 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Mon, 17 Jun 2024 17:59:04 -0700 Subject: [PATCH] chore: moving window for recent movies --- src/_data/movies.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/_data/movies.js b/src/_data/movies.js index 46c82755..8d68cc92 100644 --- a/src/_data/movies.js +++ b/src/_data/movies.js @@ -63,6 +63,7 @@ const fetchAllMovies = async () => { } export default async function () { + const year = DateTime.now().year const movies = await fetchAllMovies() const formatMovieData = (movies, watched = true) => movies.map((item) => { const movie = { @@ -89,7 +90,7 @@ export default async function () { }).filter(movie => watched ? movie['lastWatched'] : !movie['lastWatched']) const favoriteMovies = movies.filter(movie => movie['favorite']) const collectedMovies = movies.filter(movie => movie['collected']) - const recentlyWatchedMovies = movies.filter(movie => movie['last_watched']).sort((a, b) => new Date(b['last_watched']) - new Date(a['last_watched'])) + const recentlyWatchedMovies = movies.filter(movie => movie['last_watched'] && year - DateTime.fromISO(movie['last_watched']).year <= 3).sort((a, b) => new Date(b['last_watched']) - new Date(a['last_watched'])) return { movies: [...formatMovieData(movies), ...formatMovieData(movies, false)],