2023-07-08 10:36:02 +02:00
|
|
|
<script setup lang="ts">
|
2023-11-22 12:06:12 +01:00
|
|
|
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';
|
2023-11-30 23:39:47 +01:00
|
|
|
import { normalizeURL, withTrailingSlash } from 'ufo';
|
2023-07-08 10:36:02 +02:00
|
|
|
|
2023-11-30 17:18:33 +01:00
|
|
|
const nuxtApp = useNuxtApp();
|
|
|
|
|
2023-11-22 12:06:12 +01:00
|
|
|
const { t, locale, locales } = useI18n();
|
2023-07-08 10:36:02 +02:00
|
|
|
const route = useRoute();
|
2023-12-03 11:01:29 +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-12-03 14:39:42 +01:00
|
|
|
router.beforeEach((to, from) => {
|
|
|
|
if (to.path === from.path) return;
|
2023-12-03 11:01:29 +01:00
|
|
|
if (!NProgress.isStarted()) {
|
|
|
|
NProgress.start();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-11-30 17:18:33 +01:00
|
|
|
nuxtApp.hook('page:start', () => {
|
2023-12-03 11:01:29 +01:00
|
|
|
if (!NProgress.isStarted()) {
|
|
|
|
NProgress.start();
|
|
|
|
}
|
2023-10-29 14:02:27 +01:00
|
|
|
});
|
2023-11-30 17:18:33 +01:00
|
|
|
nuxtApp.hook('page:finish', () => {
|
2023-10-29 14:18:36 +01:00
|
|
|
nextTick(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
NProgress.done();
|
|
|
|
}, 100);
|
2023-11-30 17:18:33 +01:00
|
|
|
});
|
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');
|
|
|
|
}
|
|
|
|
}
|
2023-12-02 05:49:50 +01:00
|
|
|
const getTitle = () => route.meta.title ? `${route.meta.title} | ${t('_seo.siteName')}` : t('_seo.siteNameLong');
|
2023-07-08 10:36:02 +02:00
|
|
|
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": [
|
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",
|
2023-12-03 10:14:27 +01:00
|
|
|
"url": `${baseUrl}/img/icons/icon-256x256.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-11-22 12:06:12 +01:00
|
|
|
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({
|
2023-11-30 23:39:47 +01:00
|
|
|
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: {
|
2023-11-22 12:06:12 +01:00
|
|
|
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-12-01 17:20:08 +01:00
|
|
|
content: () => route.meta.thumbnail ? route.meta.thumbnail : `${baseUrl}/img/og/misskey-hub-screenshot-l.png`,
|
2023-07-10 19:54:13 +02:00
|
|
|
},
|
|
|
|
...(head.value.meta?.map((e) => ({ property: e.property, content: e.content, })) || []),
|
2023-07-08 10:36:02 +02:00
|
|
|
],
|
|
|
|
link: [
|
2023-11-30 23:39:47 +01:00
|
|
|
...(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>
|