From 9541b0745a4dc6151c8b420a4552ec4cabf52672 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 28 Apr 2025 17:22:13 -0600 Subject: [PATCH] Implement series pages --- astro.config.mjs | 1 - messages/en.json | 5 +- src/pages/series/[slug].astro | 186 ++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 src/pages/series/[slug].astro diff --git a/astro.config.mjs b/astro.config.mjs index 528cb23..3c213b5 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -51,7 +51,6 @@ export default defineConfig({ '/en/[...params]': '/[...params]', '/profile': { status: 307, destination: '/maintenance' }, '/profile/[username]': { status: 307, destination: '/maintenance' }, - '/series/[slug]': { status: 307, destination: '/maintenance' }, '/studio/[slug]': { status: 307, destination: '/maintenance' }, '/request': { status: 307, destination: '/maintenance' } }, diff --git a/messages/en.json b/messages/en.json index 336f621..38d19b1 100644 --- a/messages/en.json +++ b/messages/en.json @@ -84,5 +84,8 @@ "holy12_5": "Silksong is hidden behind one of these", "latestGameReleases": "Latest game releases", "latestAnimReleases": " Latest animation releases", - "latestReleases": "Latest releases" + "latestReleases": "Latest releases", + "firstRelease": "First Release", + "newestRelease": "Newest Release", + "variousGames": "Various Games" } diff --git a/src/pages/series/[slug].astro b/src/pages/series/[slug].astro new file mode 100644 index 0000000..0d7b887 --- /dev/null +++ b/src/pages/series/[slug].astro @@ -0,0 +1,186 @@ +--- +import prismaClient from 'utils/prisma-client' +import * as m from 'paraglide/messages' +import { getImage, Image } from 'astro:assets' +import { SEO } from 'astro-seo' + +import BaseLayout from 'layouts/base.astro' + +import AlbumBox from 'components/AlbumBox.astro' +import releaseDate from 'utils/releaseDate' + +const { slug } = Astro.params +if (!slug) return Astro.redirect('/404') + +const series = await prismaClient.series.findUnique({ + where: { slug }, + select: { + name: true, + headerColor: true, + games: { + select: { + game: { + select: { + slug: true, + releaseDate: true, + name: true, + albums: { + select: { + album: { select: { id: true, title: true, games: { select: { gameSlug: true, game: true } } } } + } + } + } + } + }, + orderBy: { game: { releaseDate: 'asc' } } + } + } +}) + +if (!series) return Astro.redirect('/404') + +const variousAlbums: { id: number; title: string | null }[] = [] +const singleAlbumsObj: { + [key: string]: { + albums: { id: number; title: string | null }[] + game: { + slug: string + name: string | null + createdAt: Date + updatedAt: Date + placeholder: string | null + headerColor: string | null + releaseDate: Date | null + } + } +} = {} +const checkedAlbums = new Set() + +series.games.forEach((g) => { + g.game.albums.forEach(({ album }) => { + if (checkedAlbums.has(album.id)) return + else checkedAlbums.add(album.id) + + if (album.games.length > 1) { + variousAlbums.push(album) + } else { + const game = album.games[0] + if (!singleAlbumsObj[game.gameSlug]) { + singleAlbumsObj[game.gameSlug] = { albums: [], game: game.game } + } + singleAlbumsObj[game.gameSlug].albums.push(album) + } + }) +}) + +const singleAlbums = Object.values(singleAlbumsObj).sort((a, b) => { + if (!a.game.releaseDate || !b.game.releaseDate) return 0 + return b.game.releaseDate.getTime() - a.game.releaseDate.getTime() +}) +const firstGame = series.games[0]?.game +const lastGame = series.games[series.games.length - 1]?.game +const coverImage = await getImage({ + src: `https://cdn.sittingonclouds.net/game/${slug}.png`, + height: 150, + width: 150 +}) +--- + + + + +
+
+
+
+ {`${series.name} +
+
+
+
+
{series.name}
+ + + { + firstGame.releaseDate ? ( + + + + + ) : null + } + { + lastGame.releaseDate ? ( + + + + + ) : null + } + +
{m.firstRelease()}: + {releaseDate(firstGame.releaseDate)} - {firstGame.name} +
{m.newestRelease()}: + {releaseDate(lastGame.releaseDate)} - {lastGame.name} +
+
+
+
+
+
+
+
{m.variousGames()}
+
+ { + variousAlbums.map((album) => ( + + )) + } +
+
+
+ { + singleAlbums.map((s) => ( +
+
+ {s.game.releaseDate?.getFullYear()} + {s.game.name} +
+
+ {s.albums.map((album) => ( + + ))} +
+
+ )) + } +
+
+
+