(fix) ブログページの全リンクから元の言語に戻れるように

This commit is contained in:
kakkokari-gtyih 2023-12-02 00:33:58 +09:00
parent 3558ea9e80
commit f653b54dd5
4 changed files with 34 additions and 9 deletions

View File

@ -1,8 +1,9 @@
export default defineAppConfig({
notice: {
title: {
ja: "v2023.11.0 をリリースしました!",
ja: "Misskeyの2023年を振り返りましょう",
en: "Recap Misskey in 2023",
},
to: "/docs/releases/"
to: "/blog/2023-12-01-2023recap/"
},
});

View File

@ -1,4 +1,5 @@
import type { NavItem } from '@nuxt/content/dist/runtime/types';
import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables';
import { parseURL } from 'ufo';
/**
@ -45,7 +46,9 @@ export function isLocalPath(link: string, base?: string): boolean {
export function sanitizeInternalPath(path: string): string {
const runtimeConfig = useRuntimeConfig();
return path.replace(new RegExp(`^(\/(${runtimeConfig.public.locales.map((l) => l.code).join('|')})\/?){2,}(.*)$`, 'g'), '$1$2');
return path
.replace(/^(\/((?!ja)[a-z]{2}))?\/blog\/(.+)/g, '/ja/blog/$3')
.replace(new RegExp(`^(\/(${(runtimeConfig.public.locales as LocaleObject[]).map((l) => l.code).join('|')})\/?){2,}(.*)$`, 'g'), '$1$2');
}
/**

View File

@ -13,7 +13,7 @@
<div class="notice h-9 w-9 rounded-full mr-2 p-2">
<MegaphoneIco class="h-5 w-5 text-white -rotate-12" />
</div>
<div class="font-bold text-sm md:text-base mr-2">{{ notice.title[locale] ?? notice.title.ja }}<ArrowRightIco v-if="isLocalPath(notice.to)" class="ml-0.5" /><ArrowUpRightIco v-else class="ml-0.5" /></div>
<div class="font-bold text-sm md:text-base mr-2">{{ notice.title[locale] ?? notice.title?.en ?? notice.title.ja }}<ArrowRightIco v-if="isLocalPath(notice.to)" class="ml-0.5" /><ArrowUpRightIco v-else class="ml-0.5" /></div>
</div>
</GNuxtLink>
</div>
@ -44,6 +44,10 @@ const showTagline = ref(false);
const colorMode = useColorMode();
const mobileScreenShot = computed(() => (colorMode.preference === 'dark') ? '/img/hero/screenshot-mobile-en.png' : '/img/hero/screenshot-mobile.png');
//
const localeState = useState('miHub_blog_originalLocale', () => locale.value);
localeState.value = locale.value;
onMounted(() => {
setTimeout(() => {
showTagline.value = true;

View File

@ -24,18 +24,35 @@
<script setup lang="ts">
import LeftIco from 'bi/arrow-left.svg';
import { joinURL, parseURL } from 'ufo';
import { isLocalPath } from '@/assets/js/misc';
import type { MiBlogParsedContent } from '~/types/content';
//
defineI18nRoute({
locales: ['ja'],
});
//
const originalLocale = useState('miHub_blog_originalLocale', () => 'ja');
const localePath = useLocalePath();
const route = useRoute();
//
const originalLocale = useState('miHub_blog_originalLocale', () => 'ja');
const localePath = useLocalePath();
const getRouteBaseName = useRouteBaseName();
let isTransformed = false;
onBeforeRouteLeave((to) => {
if (isTransformed || !isLocalPath(to.fullPath ?? to)) {
return;
}
const brn = getRouteBaseName(to);
if (!brn) {
return to;
}
isTransformed = true;
return localePath({ name: brn }, originalLocale.value);
});
//
const runtimeConfig = useRuntimeConfig();
const { data } = await useAsyncData(`blog-${route.params.slug}`, () => queryContent<MiBlogParsedContent>(`/blog/${route.params.slug}`).findOne());