jointrashposs/app.vue

124 lines
3.7 KiB
Vue
Raw Normal View History

2023-07-08 10:36:02 +02:00
<script setup lang="ts">
2023-10-29 14:02:27 +01:00
import NProgress from 'nprogress';
2023-07-08 10:36:02 +02:00
import type { Graph, Thing } from 'schema-dts';
const { t, locale } = useI18n();
const route = useRoute();
2023-10-29 14:02:27 +01:00
const router = useRouter();
2023-07-08 19:23:27 +02:00
const colorMode = useColorMode();
2023-07-10 19:54:13 +02:00
const baseUrl = useRuntimeConfig().public.baseUrl as string;
2023-07-08 19:23:27 +02:00
2023-10-29 14:02:27 +01:00
router.beforeEach(() => {
NProgress.start();
});
router.afterEach(() => {
2023-10-29 14:18:36 +01:00
nextTick(() => {
setTimeout(() => {
NProgress.done();
}, 100);
});
2023-10-29 14:02:27 +01:00
});
2023-07-08 10:36:02 +02:00
const getDescription = (): string => {
if (route.meta.description != null && route.meta.description != "") {
return route.meta.description;
} else {
return t('_seo.defaultDescription');
}
}
const getTitle = () => route.meta.title ? `${route.meta.title} | ${t('_seo.siteName')}` : t('_seo.siteName');
const getLdJson = (additionalGraphes: Thing[] = []): string => {
const ldJson: Graph = {
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
2023-07-10 19:54:13 +02:00
"@id": `${baseUrl}/#Organization`,
2023-07-08 10:36:02 +02:00
"name": "Misskey",
2023-07-10 19:54:13 +02:00
"url": `${baseUrl}/`,
2023-07-08 10:36:02 +02:00
"sameAs": [
"https://join.misskey.page/",
2023-10-29 14:18:36 +01:00
"https://ja.wikipedia.org/wiki/Misskey",
2023-07-08 10:36:02 +02:00
],
"logo": {
"@type": "ImageObject",
// TODO
2023-07-10 19:54:13 +02:00
"url": `${baseUrl}/img/logo.png`
2023-07-08 10:36:02 +02:00
}
},
{
"@type": "WebSite",
2023-07-10 19:54:13 +02:00
"@id": `${baseUrl}/#WebPage`,
2023-07-08 10:36:02 +02:00
"name": t('_seo.siteName'),
"inLanguage": locale.value,
2023-07-10 19:54:13 +02:00
"url": `${baseUrl}${route.path}`,
2023-07-08 10:36:02 +02:00
"publisher": {
"@type": "Organization",
2023-07-10 19:54:13 +02:00
"@id": `${baseUrl}/#Organization`
2023-07-08 10:36:02 +02:00
},
"headline": getTitle(),
"description": getDescription()
},
]
};
ldJson['@graph'] = ldJson['@graph'].concat(additionalGraphes);
return JSON.stringify(ldJson);
};
2023-07-10 19:54:13 +02:00
const head = useLocaleHead({
addSeoAttributes: true
});
2023-07-08 10:36:02 +02:00
useHead((): Record<string, any> => ({
htmlAttrs: {
lang: locale.value,
2023-07-09 20:09:50 +02:00
'data-bs-theme': colorMode.value,
2023-07-08 10:36:02 +02:00
},
title: getTitle(),
meta: [
{
name: "description",
content: getDescription(),
},
{
property: "og:title",
content: getTitle(),
},
2023-07-15 10:59:23 +02:00
{
property: "og:site_name",
content: t('_seo.siteName'),
},
2023-07-08 10:36:02 +02:00
{
property: "og:description",
content: getDescription(),
},
{
property: "og:image",
// TODO
2023-07-10 19:54:13 +02:00
content: () => route.meta.thumbnail ? route.meta.thumbnail : `${baseUrl}/img/logo.jpg`,
},
...(head.value.meta?.map((e) => ({ property: e.property, content: e.content, })) || []),
2023-07-08 10:36:02 +02:00
],
link: [
2023-07-10 19:54:13 +02:00
...(head.value.link?.map((e) => ({ rel: e.rel, href: (e.href.endsWith('/') ? e.href : e.href + '/'), hreflang: e.hreflang, })) || []),
2023-07-08 10:36:02 +02:00
],
script: [
{ type: "application/ld+json", children: getLdJson(route.meta.graph) }
],
}));
</script>
<template>
2023-10-29 14:18:36 +01:00
<div class="text-slate-800 dark:text-slate-200 bg-slate-100 dark:bg-gray-900">
2023-09-28 12:29:11 +02:00
<NuxtIsland name="commonNoScript">
2023-10-29 14:18:36 +01:00
<noscript class="block bg-accent-800 text-white text-center py-1.5 px-3 keep-all relative z-[10005]">Please turn
on Javascript from your browser's settings.</noscript>
2023-09-28 12:29:11 +02:00
</NuxtIsland>
2023-10-29 14:18:36 +01:00
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
2023-07-12 15:50:26 +02:00
<ClientOnly>
2023-07-16 13:23:03 +02:00
<LazyGAiChan />
2023-07-12 15:50:26 +02:00
</ClientOnly>
2023-10-29 14:18:36 +01:00
</div>
2023-07-08 10:36:02 +02:00
</template>