Update hash removal pattern

This commit is contained in:
thiloho
2025-04-27 11:26:30 +02:00
parent 5c5b1cebe5
commit 2415c37987

View File

@@ -7,19 +7,17 @@ const albumCovers = await Astro.glob("../content/album-covers/*");
const processedAlbumCovers = albumCovers.map((cover) => { const processedAlbumCovers = albumCovers.map((cover) => {
const filePathWithoutParams = cover.default.src.split("?")[0]; const filePathWithoutParams = cover.default.src.split("?")[0];
const filename = parse(filePathWithoutParams).name; const filename = parse(filePathWithoutParams).name;
const lastDashIndex = filename.lastIndexOf(" - "); const lastDashIndex = filename.lastIndexOf(" - ");
const artists = let artists =
lastDashIndex !== -1 ? filename.substring(0, lastDashIndex) : filename; lastDashIndex !== -1 ? filename.substring(0, lastDashIndex) : filename;
let title = lastDashIndex !== -1 ? filename.substring(lastDashIndex + 3) : ""; let title = lastDashIndex !== -1 ? filename.substring(lastDashIndex + 3) : "";
if (import.meta.env.PROD) { if (import.meta.env.PROD) {
const lastDotIndex = filename.lastIndexOf("."); title = title.replace(/\..{8}$/, "");
title = lastDotIndex !== -1 ? filename.substring(0, lastDotIndex) : ""; artists = artists.replaceAll("_", ",");
} }
return { cover, filename, artists, title }; return { cover, filename, artists, title };
@@ -46,7 +44,7 @@ const sortedAlbumCovers = processedAlbumCovers.sort((a, b) =>
sortedAlbumCovers.map(({ cover, filename, artists, title }) => ( sortedAlbumCovers.map(({ cover, filename, artists, title }) => (
<figure> <figure>
<a <a
href={`https://music.youtube.com/search?q=${encodeURIComponent(filename)}`} href={`https://music.youtube.com/search?q=${encodeURIComponent(`${title} - ${artists}`)}`}
> >
<Image <Image
src={cover.default} src={cover.default}