jointrashposs/app.vue

140 lines
4.5 KiB
Vue
Raw Normal View History

2023-07-08 10:36:02 +02:00
<script setup lang="ts">
import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables';
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';
import { normalizeURL, withTrailingSlash } from 'ufo';
2023-07-08 10:36:02 +02:00
const nuxtApp = useNuxtApp();
const { t, locale, locales } = useI18n();
2023-07-08 10:36:02 +02:00
const route = useRoute();
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
nuxtApp.hook('page:start', () => {
2023-10-29 14:02:27 +01:00
NProgress.start();
});
nuxtApp.hook('page:finish', () => {
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);
};
const currentLocaleIso = computed(() => (locales.value as LocaleObject[]).find((e) => e?.code === locale.value)?.iso);
2023-07-08 10:36:02 +02:00
2023-07-10 19:54:13 +02:00
const head = useLocaleHead({
addSeoAttributes: true,
2023-07-10 19:54:13 +02:00
});
2023-10-29 15:30:59 +01:00
/**
* 中国大陸で Google Fonts を使う裏技
* fonts.googleapis.com fonts.googleapis.cn
**/
const cnHead = (locale.value === 'cn') ? [
2023-11-03 08:55:33 +01:00
{ rel: 'preconnect', href: 'https://fonts.googleapis.cn' },
{ rel: 'preconnect', href: 'https://fonts.gstatic.cn' },
2023-10-29 15:30:59 +01:00
{ rel: 'stylesheet', href: 'https://fonts.googleapis.cn/css2?family=Capriola&family=Nunito:ital,wght@0,400;0,700;1,400;1,700&display=swap' }
2023-11-03 08:55:33 +01:00
] : [
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{ rel: 'preconnect', href: 'https://fonts.gstatic.com' },
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Capriola&family=Nunito:ital,wght@0,400;0,700;1,400;1,700&display=swap' },
];
2023-10-29 15:30:59 +01:00
2023-07-08 10:36:02 +02:00
useHead((): Record<string, any> => ({
htmlAttrs: {
lang: currentLocaleIso.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: [
...(head.value.link?.map((e) => ({ rel: e.rel, href: normalizeURL(withTrailingSlash(e.href)), hreflang: e.hreflang, })) || []),
2023-10-29 15:30:59 +01:00
...cnHead,
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-11-15 13:23:19 +01:00
<NuxtIsland name="GNoScript" />
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>