Initial commit
This commit is contained in:
commit
acadc92e68
780 files changed
+468285
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<script setup>
|
||||
import PlayerPage from "~/components/PlayerPage.vue";
|
||||
import { getBaseHead } from "~/utils/head";
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
|
||||
const activeSong = useState("activeSong", () => null);
|
||||
activeSong.value = null;
|
||||
|
||||
const requestUrl = useRequestURL();
|
||||
const homeTitle = t("app.homeTitle") || t("app.title");
|
||||
const description = t("app.description");
|
||||
|
||||
useHead(() => ({
|
||||
...getBaseHead(locale.value),
|
||||
title: homeTitle,
|
||||
}));
|
||||
|
||||
useSeoMeta({
|
||||
title: homeTitle,
|
||||
description: description,
|
||||
ogTitle: homeTitle,
|
||||
ogDescription: description,
|
||||
ogType: "website",
|
||||
ogUrl: requestUrl.href,
|
||||
twitterCard: "summary",
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const rawId = Array.isArray(route.query.id)
|
||||
? route.query.id[0]
|
||||
: route.query.id;
|
||||
const parsedId = rawId ? Number.parseInt(String(rawId), 10) : NaN;
|
||||
|
||||
if (Number.isFinite(parsedId) && parsedId > 0) {
|
||||
const { data } = await useFetch(`/api/song/${parsedId}`, { server: true });
|
||||
const fileName = data.value?.fileName;
|
||||
if (typeof fileName === "string" && fileName) {
|
||||
await navigateTo(`/song/${parsedId}/${encodeURIComponent(fileName)}`, {
|
||||
redirectCode: 301,
|
||||
replace: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PlayerPage />
|
||||
</template>
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup>
|
||||
import { createError } from "h3";
|
||||
import PlayerPage from "~/components/PlayerPage.vue";
|
||||
import { getBaseHead } from "~/utils/head";
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const route = useRoute();
|
||||
|
||||
const rawId = Array.isArray(route.params.id)
|
||||
? route.params.id[0]
|
||||
: route.params.id;
|
||||
const parsedId = rawId ? Number.parseInt(String(rawId), 10) : NaN;
|
||||
|
||||
if (!Number.isFinite(parsedId) || parsedId < 1) {
|
||||
throw createError({ statusCode: 404, statusMessage: "Song not found" });
|
||||
}
|
||||
|
||||
const { data, error } = await useFetch(`/api/song/${parsedId}`, {
|
||||
server: true,
|
||||
});
|
||||
|
||||
if (error.value || !data.value?.fileName) {
|
||||
throw createError({ statusCode: 404, statusMessage: "Song not found" });
|
||||
}
|
||||
|
||||
const fileName = data.value.fileName;
|
||||
const activeSong = useState("activeSong", () => null);
|
||||
activeSong.value = {
|
||||
id: parsedId,
|
||||
fileName: fileName,
|
||||
title: formatSongTitle(fileName),
|
||||
};
|
||||
const rawFileParam = Array.isArray(route.params.songFileName)
|
||||
? route.params.songFileName[0]
|
||||
: route.params.songFileName;
|
||||
const decodedParam = rawFileParam ? safeDecode(String(rawFileParam)) : "";
|
||||
const canonicalPath = `/song/${parsedId}/${encodeURIComponent(fileName)}`;
|
||||
|
||||
if (decodedParam && decodedParam !== fileName) {
|
||||
await navigateTo(canonicalPath, { redirectCode: 301 });
|
||||
}
|
||||
|
||||
const baseTitle = t("app.title");
|
||||
const displayTitle = formatSongTitle(fileName);
|
||||
const pageTitle = displayTitle ? `${displayTitle} - ${baseTitle}` : baseTitle;
|
||||
const description = displayTitle
|
||||
? `Listen to ${displayTitle} (${fileName}) with ${baseTitle}.`
|
||||
: `Listen to tracker music with ${baseTitle}.`;
|
||||
|
||||
const requestUrl = useRequestURL();
|
||||
const canonicalUrl = `${requestUrl.origin}${canonicalPath}`;
|
||||
|
||||
useHead(() => {
|
||||
const head = getBaseHead(locale.value);
|
||||
const structuredData = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "MusicRecording",
|
||||
"name": displayTitle || fileName,
|
||||
"url": canonicalUrl,
|
||||
"audio": {
|
||||
"@type": "AudioObject",
|
||||
"name": fileName,
|
||||
"contentUrl": `${requestUrl.origin}/api/music/${encodeURIComponent(fileName)}`,
|
||||
},
|
||||
};
|
||||
return {
|
||||
...head,
|
||||
link: [...(head.link || []), { rel: "canonical", href: canonicalUrl }],
|
||||
script: [
|
||||
...(head.script || []),
|
||||
{
|
||||
type: "application/ld+json",
|
||||
innerHTML: JSON.stringify(structuredData),
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
useSeoMeta({
|
||||
title: pageTitle,
|
||||
description,
|
||||
ogTitle: pageTitle,
|
||||
ogDescription: description,
|
||||
ogType: "music.song",
|
||||
ogUrl: canonicalUrl,
|
||||
twitterCard: "summary",
|
||||
});
|
||||
|
||||
function formatSongTitle(name) {
|
||||
if (!name || typeof name !== "string") return "";
|
||||
const withoutExt = name.replace(/\.[^.]+$/, "");
|
||||
const normalized = withoutExt.replace(/[._-]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
return normalized || name;
|
||||
}
|
||||
|
||||
function safeDecode(value) {
|
||||
try {
|
||||
return decodeURIComponent(value);
|
||||
} catch (error) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PlayerPage />
|
||||
</template>
|
||||
Reference in new issue
Block a user