mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-24 17:59:07 +01:00
(fix) ブログページの全リンクから元の言語に戻れるように
This commit is contained in:
parent
3558ea9e80
commit
f653b54dd5
@ -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/"
|
||||
},
|
||||
});
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user