diff --git a/.gitignore b/.gitignore index ec90e464..e3845696 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .nuxt .nitro .cache +.vercel dist # Node dependencies diff --git a/app.vue b/app.vue index 559cec30..4577ba70 100644 --- a/app.vue +++ b/app.vue @@ -2,24 +2,24 @@ import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables'; import NProgress from 'nprogress'; import type { Graph, Thing } from 'schema-dts'; +import { normalizeURL, withTrailingSlash } from 'ufo'; + +const nuxtApp = useNuxtApp(); const { t, locale, locales } = useI18n(); const route = useRoute(); -const router = useRouter(); const colorMode = useColorMode(); const baseUrl = useRuntimeConfig().public.baseUrl as string; -router.beforeEach((to, from) => { - if (to.path === from.path) return; +nuxtApp.hook('page:start', () => { NProgress.start(); }); -router.afterEach((to, from) => { - if (to.path === from.path) return; +nuxtApp.hook('page:finish', () => { nextTick(() => { setTimeout(() => { NProgress.done(); }, 100); - }); + }); }); const getDescription = (): string => { @@ -70,7 +70,7 @@ const getLdJson = (additionalGraphes: Thing[] = []): string => { const currentLocaleIso = computed(() => (locales.value as LocaleObject[]).find((e) => e?.code === locale.value)?.iso); const head = useLocaleHead({ - addSeoAttributes: true + addSeoAttributes: true, }); /** @@ -118,7 +118,7 @@ useHead((): Record => ({ ...(head.value.meta?.map((e) => ({ property: e.property, content: e.content, })) || []), ], link: [ - ...(head.value.link?.map((e) => ({ rel: e.rel, href: (e.href.endsWith('/') ? e.href : e.href + '/'), hreflang: e.hreflang, })) || []), + ...(head.value.link?.map((e) => ({ rel: e.rel, href: normalizeURL(withTrailingSlash(e.href)), hreflang: e.hreflang, })) || []), ...cnHead, ], script: [ diff --git a/content/.README.md b/content/.README.md index ea6e4704..a6db678e 100644 --- a/content/.README.md +++ b/content/.README.md @@ -37,6 +37,13 @@ VuePressでは末尾が`.md`となるパス形式でしたが、Misskey-Hub-Next date: 2023-11-11 ``` +### `thumbnail` +(現状ブログのみ)サムネイル画像を設定できます。URLまたはサイトディレクトリの絶対パスを入力してください + +```yml +thumbnail: /img/blog/foo/bar.png +``` + ### `maxTocDepth` (Docsのみ)もくじの見出しを遡る限度を指定できます。`

`タグまでにしたい場合は`2`を指定します。 diff --git a/nuxt.config.ts b/nuxt.config.ts index 18e97132..4e08f344 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,11 +1,11 @@ // https://nuxt.com/docs/api/configuration/nuxt-config import yaml from '@rollup/plugin-yaml'; import svgLoader from 'vite-svg-loader'; -import { cpus } from 'node:os'; -import genSitemap from './scripts/gen-sitemap'; import { genApiTranslationFiles } from './scripts/gen-api-translations'; import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables'; import { genLocalesJson } from './scripts/gen-locales'; +import { getStaticEndpoints } from './scripts/get-static-endpoints'; +import type { NuxtConfig } from 'nuxt/schema'; // 公開時のドメイン(末尾スラッシュなし) const baseUrl = 'https://misskey-hub.net'; @@ -27,6 +27,41 @@ export type LocaleCodes = typeof localesConst[number]['code']; export const locales = localesConst as unknown as LocaleObject[]; +function getRouteRules(): NuxtConfig['routeRules'] { + // 言語ごとに割り当てる必要のないRouteRules + const staticRules: NuxtConfig['routeRules'] = { + '/ja/blog/**': { isr: true }, + '/ns/': { prerender: true }, + }; + + // それぞれの言語について割り当てる必要のあるRouteRules + const localeBasedRules: NuxtConfig['routeRules'] = { + '/docs/**': { isr: true }, + }; + + // 静的ページをすべて追加 + getStaticEndpoints().forEach((route) => { + if (!route.includes('ns')) { + localeBasedRules[route] = { prerender: true }; + staticRules[route] = { prerender: true }; + } + }); + + // 言語ごとにすべて割り当てていく + const _localeBasedRules: NuxtConfig['routeRules'] = {}; + const localeCodes = locales.map((v) => v.code); + Object.keys(localeBasedRules).forEach((route) => { + localeCodes.forEach((code) => { + _localeBasedRules[`/${code}${route}`] = localeBasedRules[route]; + }); + }) + + return { + ...staticRules, + ..._localeBasedRules, + }; +} + export default defineNuxtConfig({ runtimeConfig: { public: { @@ -114,17 +149,7 @@ export default defineNuxtConfig({ ], }, nitro: { - hooks: { - 'compiled': genSitemap, - }, - prerender: { - concurrency: cpus().length * 8 ?? 12, - routes: [ - "/404.html" - ], - // 【一時対応】とりあえずビルドできるようにする - failOnError: false, - }, + preset: 'vercel', plugins: [ '@/server/plugins/appendComment.ts', '@/server/plugins/i18nRedirector.ts', @@ -141,4 +166,5 @@ export default defineNuxtConfig({ payloadExtraction: true, componentIslands: true, }, -}) + routeRules: getRouteRules(), +}); diff --git a/package.json b/package.json index d54906a3..f40b410c 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,6 @@ "@types/js-yaml": "^4.0.9", "@types/node": "^20.9.1", "@types/nprogress": "^0.2.3", - "@types/rellax": "^1.7.7", - "@types/three": "^0.158.2", - "@types/tinycolor2": "^1.4.6", "aiscript-vscode": "github:aiscript-dev/aiscript-vscode#v0.0.5", "autoprefixer": "^10.4.16", "bootstrap": "^5.3.2", @@ -30,15 +27,12 @@ "mfm-js": "^0.23.3", "misskey-js": "^0.0.16", "nprogress": "^0.2.0", - "nuxt": "^3.8.1", + "nuxt": "^3.8.2", "postcss": "^8.4.31", - "rellax": "^1.12.1", "sass": "^1.69.5", "schema-dts": "^1.1.2", "sitemap": "^7.1.1", "tailwindcss": "^3.3.5", - "three": "^0.158.0", - "tinycolor2": "^1.6.0", "ufo": "^1.3.2", "vite-svg-loader": "^4.0.0" }, diff --git a/pages/blog/[slug].vue b/pages/blog/[slug].vue index d0e09061..0efac064 100644 --- a/pages/blog/[slug].vue +++ b/pages/blog/[slug].vue @@ -5,8 +5,8 @@

{{ $t('_blog.title') }}

-

{{ data.title }}

-

{{ $d(new Date(data.date)) }}

+

{{ data?.title }}

+

{{ $d(new Date(data?.date)) }}

@@ -23,6 +23,8 @@