From f675e177b7f866d8ddc2439655df634447cc3290 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 24 Mar 2025 11:52:39 -0600 Subject: [PATCH 1/5] Improve search result order by relevance --- src/components/search/AlbumSearch.astro | 31 ++++++++----------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/components/search/AlbumSearch.astro b/src/components/search/AlbumSearch.astro index 6016d99..71ba34b 100644 --- a/src/components/search/AlbumSearch.astro +++ b/src/components/search/AlbumSearch.astro @@ -11,31 +11,20 @@ interface Props { const take = 20 const { query } = Astro.props + +const queryString = query + .toLowerCase() + .split('_') + .map((w) => `+${w}`) + .join(' ') const findQuery: Prisma.albumsFindManyArgs = { select: { title: true, releaseDate: true, id: true }, where: { - OR: [ - { - title: { - search: query - .toLowerCase() - .split('_') - .map((w) => `+${w}`) - .join(' ') - } - }, - { - subTitle: { - search: query - .toLowerCase() - .split('_') - .map((w) => `+${w}`) - .join(' ') - } - } - ] + OR: [{ title: { search: queryString } }, { subTitle: { search: queryString } }] }, - orderBy: { publishedAt: 'desc' } + orderBy: { + _relevance: { fields: ['title', 'subTitle'], sort: 'desc', search: query.toLowerCase() } + } } const countQuery: Prisma.albumsCountArgs = { where: findQuery.where From d618e30110ccc277b30be33f57746102c3f1f71c Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 24 Mar 2025 13:31:55 -0600 Subject: [PATCH 2/5] Implement holy12 page --- astro.config.mjs | 1 - messages/en.json | 8 ++++++- src/components/Sidebar.astro | 2 +- src/pages/holy12.astro | 42 ++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/pages/holy12.astro diff --git a/astro.config.mjs b/astro.config.mjs index 9efff5a..bc7ed16 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -62,7 +62,6 @@ export default defineConfig({ '/series/list': { status: 307, destination: '/maintenance' }, '/studio/[slug]': { status: 307, destination: '/maintenance' }, '/studio/list': { status: 307, destination: '/maintenance' }, - '/holy12': { status: 307, destination: '/maintenance' }, '/request': { status: 307, destination: '/maintenance' } }, security: { diff --git a/messages/en.json b/messages/en.json index 0e3e919..87c78bb 100644 --- a/messages/en.json +++ b/messages/en.json @@ -75,5 +75,11 @@ "discordRoleNeeded": "You need the Donator Discord role to access this page", "addedDonator": "Added donator benefits to your account!", "errorDonatorCheck": "Something went wrong when checking your Discord donator status. Please try again later. {error}", - "discordRateLimit": "{message} Retry after {retry_after} seconds." + "discordRateLimit": "{message} Retry after {retry_after} seconds.", + "holy12_0": "Cloud's secret mixtape", + "holy12_1": "Best romantic dinner BGM", + "holy12_2": "12 clicks till midnight", + "holy12_3": "We let our technicians pick these", + "holy12_4": "It's noisy outside, take one of these", + "holy12_5": "Silksong is hidden behind one of these" } diff --git a/src/components/Sidebar.astro b/src/components/Sidebar.astro index 144e8b7..f0d801e 100644 --- a/src/components/Sidebar.astro +++ b/src/components/Sidebar.astro @@ -20,7 +20,7 @@ const listClass =
{m.getLucky()} - {m.randomPull()} + {m.randomPull()}
diff --git a/src/pages/holy12.astro b/src/pages/holy12.astro new file mode 100644 index 0000000..41c0319 --- /dev/null +++ b/src/pages/holy12.astro @@ -0,0 +1,42 @@ +--- +import * as m from 'paraglide/messages' +import prismaClient from 'utils/prisma-client' + +import Base from 'layouts/base.astro' +import { getRandom } from 'utils/form' +import AlbumBox from 'components/AlbumBox.astro' + +async function getRandomAlbum(): Promise<{ id: number; title: string }> { + const res: { id: number; title: string }[] = await prismaClient.$queryRawUnsafe(` + SELECT r1.id as id, r1.title as title + FROM albums AS r1 JOIN ( + SELECT ( + RAND() * ( + SELECT MAX(id) FROM albums + ) + ) AS id + ) AS r2 + WHERE r1.id >= r2.id + ORDER BY r1.id ASC + LIMIT 1;`) + + return res[0] +} + +const titles = [m.holy12_0(), m.holy12_1(), m.holy12_2(), m.holy12_3(), m.holy12_4(), m.holy12_5()] +const title = getRandom(titles) +const albums: { id: number; title: string }[] = await Promise.all(Array.from({ length: 12 }, getRandomAlbum)) +--- + + +
+

{title}

+
+ { + albums.map((album) => ( + + )) + } +
+
+ From 5c8f8be7911372ab9d3718628b99e349476e6ad4 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 24 Mar 2025 13:47:31 -0600 Subject: [PATCH 3/5] Make letter sections in album list deferred --- src/pages/album/list/index.astro | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pages/album/list/index.astro b/src/pages/album/list/index.astro index 1b78507..53274cc 100644 --- a/src/pages/album/list/index.astro +++ b/src/pages/album/list/index.astro @@ -1,11 +1,8 @@ --- import prismaClient from 'utils/prisma-client' -import * as m from 'paraglide/messages' -import { AlbumStatus } from '@prisma/client' -import Sidebar from 'components/Sidebar.astro' import BaseLayout from 'layouts/base.astro' -import AlbumBox from 'components/AlbumBox.astro' +import Sidebar from 'components/Sidebar.astro' import LetterSection from 'components/albumList/letterSection.astro' const letters: { letter: string; count: BigInt }[] = await prismaClient.$queryRaw` @@ -40,7 +37,15 @@ const letters: { letter: string; count: BigInt }[] = await prismaClient.$queryRa
{l.letter}
- + + +
+ {Array.from({ length: Number(l.count) }).map(() => ( +
+ ))} +
+ +
)) From 91a91cb6a3d332905f9f519a3ecb00e4fb378c70 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 24 Mar 2025 14:00:44 -0600 Subject: [PATCH 4/5] Implement Get Lucky sidebar button --- src/components/Sidebar.astro | 5 ++++- src/components/sidebar/GetLuckyAlbum.astro | 14 ++++++++++++++ src/pages/holy12.astro | 22 +++------------------- src/utils/queries.ts | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 src/components/sidebar/GetLuckyAlbum.astro create mode 100644 src/utils/queries.ts diff --git a/src/components/Sidebar.astro b/src/components/Sidebar.astro index f0d801e..722a70c 100644 --- a/src/components/Sidebar.astro +++ b/src/components/Sidebar.astro @@ -13,13 +13,16 @@ import AlbumBox from './AlbumBox.astro' import AlbumCount from './sidebar/AlbumCount.astro' import CommentCarousel from './sidebar/CommentCarousel.astro' import SidebarAd from './sidebar/SidebarAd.astro' +import GetLuckyAlbum from './sidebar/GetLuckyAlbum.astro' const listClass = 'uppercase text-3xl font-semibold w-full text-center py-3 hover:bg-dark-hover hover:text-cyan-400 hover:underline' ---
- {m.getLucky()} + +
+
{m.randomPull()}
diff --git a/src/components/sidebar/GetLuckyAlbum.astro b/src/components/sidebar/GetLuckyAlbum.astro new file mode 100644 index 0000000..9ff952b --- /dev/null +++ b/src/components/sidebar/GetLuckyAlbum.astro @@ -0,0 +1,14 @@ +--- +interface Props { + class: string +} + +import * as m from '../../paraglide/messages.js' + +import { getRandomAlbum } from 'utils/queries' + +const album = await getRandomAlbum() +const { class: className } = Astro.props +--- + +{m.getLucky()} diff --git a/src/pages/holy12.astro b/src/pages/holy12.astro index 41c0319..465e9a5 100644 --- a/src/pages/holy12.astro +++ b/src/pages/holy12.astro @@ -1,28 +1,12 @@ --- import * as m from 'paraglide/messages' -import prismaClient from 'utils/prisma-client' + +import { getRandom } from 'utils/form' +import { getRandomAlbum } from 'utils/queries' import Base from 'layouts/base.astro' -import { getRandom } from 'utils/form' import AlbumBox from 'components/AlbumBox.astro' -async function getRandomAlbum(): Promise<{ id: number; title: string }> { - const res: { id: number; title: string }[] = await prismaClient.$queryRawUnsafe(` - SELECT r1.id as id, r1.title as title - FROM albums AS r1 JOIN ( - SELECT ( - RAND() * ( - SELECT MAX(id) FROM albums - ) - ) AS id - ) AS r2 - WHERE r1.id >= r2.id - ORDER BY r1.id ASC - LIMIT 1;`) - - return res[0] -} - const titles = [m.holy12_0(), m.holy12_1(), m.holy12_2(), m.holy12_3(), m.holy12_4(), m.holy12_5()] const title = getRandom(titles) const albums: { id: number; title: string }[] = await Promise.all(Array.from({ length: 12 }, getRandomAlbum)) diff --git a/src/utils/queries.ts b/src/utils/queries.ts new file mode 100644 index 0000000..8ae49a7 --- /dev/null +++ b/src/utils/queries.ts @@ -0,0 +1,18 @@ +import prismaClient from './prisma-client' + +export async function getRandomAlbum(): Promise<{ id: number; title: string }> { + const res: { id: number; title: string }[] = await prismaClient.$queryRawUnsafe(` + SELECT r1.id as id, r1.title as title + FROM albums AS r1 JOIN ( + SELECT ( + RAND() * ( + SELECT MAX(id) FROM albums + ) + ) AS id + ) AS r2 + WHERE r1.id >= r2.id + ORDER BY r1.id ASC + LIMIT 1;`) + + return res[0] +} From 491d72bd3c4abaa2915abaa27be12d6e3de0036b Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Mon, 24 Mar 2025 16:32:15 -0600 Subject: [PATCH 5/5] Anim and game releases pages --- astro.config.mjs | 2 -- messages/en.json | 5 +++- src/components/Header.astro | 19 +++++++----- src/layouts/PaginatedAlbumList.astro | 42 ++++++++++++++++++++++++++ src/pages/anim/latest/[...page].astro | 28 +++++++++++++++++ src/pages/game/latest/[...page].astro | 28 +++++++++++++++++ src/pages/last-added/[...page].astro | 43 +++++---------------------- 7 files changed, 122 insertions(+), 45 deletions(-) create mode 100644 src/layouts/PaginatedAlbumList.astro create mode 100644 src/pages/anim/latest/[...page].astro create mode 100644 src/pages/game/latest/[...page].astro diff --git a/astro.config.mjs b/astro.config.mjs index bc7ed16..2d35aa0 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -48,10 +48,8 @@ export default defineConfig({ output: 'server', adapter: node({ mode: 'standalone' }), redirects: { - '/anim': { status: 307, destination: '/maintenance' }, '/anim/[id]': { status: 307, destination: '/maintenance' }, '/anim/list': { status: 307, destination: '/maintenance' }, - '/game': { status: 307, destination: '/maintenance' }, '/game/[slug]': { status: 307, destination: '/maintenance' }, '/game/list': { status: 307, destination: '/maintenance' }, '/platform/list': { status: 307, destination: '/maintenance' }, diff --git a/messages/en.json b/messages/en.json index 87c78bb..336f621 100644 --- a/messages/en.json +++ b/messages/en.json @@ -81,5 +81,8 @@ "holy12_2": "12 clicks till midnight", "holy12_3": "We let our technicians pick these", "holy12_4": "It's noisy outside, take one of these", - "holy12_5": "Silksong is hidden behind one of these" + "holy12_5": "Silksong is hidden behind one of these", + "latestGameReleases": "Latest game releases", + "latestAnimReleases": " Latest animation releases", + "latestReleases": "Latest releases" } diff --git a/src/components/Header.astro b/src/components/Header.astro index af839bb..ee3241d 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,6 +1,7 @@ --- import { Image, Picture } from 'astro:assets' import * as m from '../paraglide/messages.js' +import prismaClient from 'utils/prisma-client.js' import logo from 'img/logos/winter.png' import logoEs from 'img/logos/default_es.png' @@ -10,12 +11,16 @@ import DropdownItem from './header/DropdownItem.astro' import Toggler from './header/Toggler.astro' import NavButton from './header/NavButton.astro' import LoginNav from './header/LoginNav.astro' -import prismaClient from 'utils/prisma-client.js' -import { Icon } from 'astro-icon/components' import SearchBar from './search/SearchBar.astro' -const { value: bannerId } = (await prismaClient.config.findUnique({ where: { name: 'banner' } })) ?? {} -const { value: bannerPosition } = (await prismaClient.config.findUnique({ where: { name: 'banner-position' } })) ?? {} +const [bannerConfig, bannerPositionConfig] = await Promise.all([ + prismaClient.config.findUnique({ where: { name: 'banner' }, select: { value: true } }), + prismaClient.config.findUnique({ where: { name: 'banner-position' }, select: { value: true } }) +]) + +const bannerId = bannerConfig?.value || '' +const bannerPosition = bannerPositionConfig?.value || 'top' + const { session } = Astro.locals --- @@ -53,18 +58,18 @@ const { session } = Astro.locals {m.games()} - {m.albums()} + {m.latestReleases()} + {m.gamelist()} {m.series()} {m.publishers()} {m.platforms()} - {m.gamelist()} {m.animation()} - {m.albums()} + {m.latestReleases()} {m.animationlist()} {m.studios()} diff --git a/src/layouts/PaginatedAlbumList.astro b/src/layouts/PaginatedAlbumList.astro new file mode 100644 index 0000000..34bc19b --- /dev/null +++ b/src/layouts/PaginatedAlbumList.astro @@ -0,0 +1,42 @@ +--- +interface Props { + albums: { title: string | null; id: number }[] + limitXS: number + limitMD: number + fullPageList: number[] + page: number +} + +import Base from './base.astro' +import AlbumBox from 'components/AlbumBox.astro' +import FooterNav from 'components/lastAdded/FooterNav.astro' + +const { albums, limitMD, limitXS, ...listProps } = Astro.props + +if (albums.length === 0) { + Astro.redirect('/404') +} +--- + + +
+
+
+

+ +

+
+ { + albums.map((album) => ( + + )) + } +
+
+
+ +
+ diff --git a/src/pages/anim/latest/[...page].astro b/src/pages/anim/latest/[...page].astro new file mode 100644 index 0000000..2c015a2 --- /dev/null +++ b/src/pages/anim/latest/[...page].astro @@ -0,0 +1,28 @@ +--- +import prismaClient from 'utils/prisma-client' +import * as m from 'paraglide/messages' +import { AlbumStatus } from '@prisma/client' + +import PaginatedAlbumList from 'layouts/PaginatedAlbumList.astro' + +const page = Math.min(1, parseInt(Astro.params.page ?? '1')) +const take = 40 +const limitMD = 12 +const limitXS = 5 + +const albums = await prismaClient.albums.findMany({ + where: { status: AlbumStatus.SHOW, categories: { some: { categoryName: 'Animation' } } }, + select: { id: true, title: true }, + take, + skip: take * (page - 1), + orderBy: [{ releaseDate: 'desc' }, { publishedAt: 'desc' }, { createdAt: 'desc' }] +}) +const count = await prismaClient.albums.count({ where: { status: AlbumStatus.SHOW } }) + +const fullPageList = [...Array(Math.ceil(count / take))].map((v, i) => i + 1) +const listProps = { fullPageList, page, albums, limitMD, limitXS } +--- + + + {m.latestAnimReleases()} + diff --git a/src/pages/game/latest/[...page].astro b/src/pages/game/latest/[...page].astro new file mode 100644 index 0000000..63f9aae --- /dev/null +++ b/src/pages/game/latest/[...page].astro @@ -0,0 +1,28 @@ +--- +import prismaClient from 'utils/prisma-client' +import * as m from 'paraglide/messages' +import { AlbumStatus } from '@prisma/client' + +import PaginatedAlbumList from 'layouts/PaginatedAlbumList.astro' + +const page = Math.min(1, parseInt(Astro.params.page ?? '1')) +const take = 40 +const limitMD = 12 +const limitXS = 5 + +const albums = await prismaClient.albums.findMany({ + where: { status: AlbumStatus.SHOW, categories: { some: { categoryName: 'Game' } } }, + select: { id: true, title: true }, + take, + skip: take * (page - 1), + orderBy: [{ releaseDate: 'desc' }, { publishedAt: 'desc' }, { createdAt: 'desc' }] +}) +const count = await prismaClient.albums.count({ where: { status: AlbumStatus.SHOW } }) + +const fullPageList = [...Array(Math.ceil(count / take))].map((v, i) => i + 1) +const listProps = { fullPageList, page, albums, limitMD, limitXS } +--- + + + {m.latestGameReleases()} + diff --git a/src/pages/last-added/[...page].astro b/src/pages/last-added/[...page].astro index 61c02da..959b44f 100644 --- a/src/pages/last-added/[...page].astro +++ b/src/pages/last-added/[...page].astro @@ -3,53 +3,26 @@ import prismaClient from 'utils/prisma-client' import * as m from 'paraglide/messages' import { AlbumStatus } from '@prisma/client' -import BaseLayout from 'layouts/base.astro' -import AlbumBox from 'components/AlbumBox.astro' -import FooterNav from 'components/lastAdded/FooterNav.astro' +import PaginatedAlbumList from 'layouts/PaginatedAlbumList.astro' -const page = parseInt(Astro.params.page ?? '1') +const page = Math.min(1, parseInt(Astro.params.page ?? '1')) const take = 40 const limitMD = 12 const limitXS = 5 -if (page < 1) { - Astro.redirect('/last-added') -} - -const lastAlbums = await prismaClient.albums.findMany({ +const albums = await prismaClient.albums.findMany({ where: { status: AlbumStatus.SHOW }, select: { id: true, title: true }, take, skip: take * (page - 1), - orderBy: { createdAt: 'desc' } + orderBy: { publishedAt: 'desc' } }) const count = await prismaClient.albums.count({ where: { status: AlbumStatus.SHOW } }) -if (lastAlbums.length === 0) { - Astro.redirect('/404') -} - const fullPageList = [...Array(Math.ceil(count / take))].map((v, i) => i + 1) -const listProps = { fullPageList, page } +const listProps = { fullPageList, page, albums, limitMD, limitXS } --- - -
-
-

- {m.lastAdded()} -

-
- { - lastAlbums.map((album) => ( - - )) - } -
-
- -
-
+ + {m.lastAdded()} +