From 3606edd9675b0b7a15660faae1ec220e594ef706 Mon Sep 17 00:00:00 2001 From: thiloho <123883702+thiloho@users.noreply.github.com> Date: Sun, 27 Apr 2025 11:01:21 +0200 Subject: [PATCH] Update hash removal pattern --- src/pages/tracks.astro | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pages/tracks.astro b/src/pages/tracks.astro index 3f24a01..0b2d641 100644 --- a/src/pages/tracks.astro +++ b/src/pages/tracks.astro @@ -8,18 +8,20 @@ const albumCovers = await Astro.glob("../content/album-covers/*"); const processedAlbumCovers = albumCovers.map((cover) => { const filePathWithoutParams = cover.default.src.split("?")[0]; - let filename = parse(filePathWithoutParams).name; - - const lastDotIndex = filename.lastIndexOf("."); - if (lastDotIndex !== -1) { - filename = filename.substring(0, lastDotIndex); - } + const filename = parse(filePathWithoutParams).name; const lastDashIndex = filename.lastIndexOf(" - "); + const artists = lastDashIndex !== -1 ? filename.substring(0, lastDashIndex) : filename; - const title = - lastDashIndex !== -1 ? filename.substring(lastDashIndex + 3) : ""; + + let title = lastDashIndex !== -1 ? filename.substring(lastDashIndex + 3) : ""; + + const lastDotIndex = title.lastIndexOf("."); + + if (lastDotIndex !== -1 && import.meta.env.PROD) { + title = filename.substring(0, lastDotIndex); + } return { cover, filename, artists, title }; });