mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-22 00:43:50 +01:00
fix internal paths
This commit is contained in:
parent
e2a753bef5
commit
c812abe139
@ -43,6 +43,11 @@ export function isLocalPath(link: string, base?: string): boolean {
|
|||||||
return (!url.host || rootDomain.host === url.host);
|
return (!url.host || rootDomain.host === url.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ナビゲーションObjectを合致する条件まで深掘り
|
* ナビゲーションObjectを合致する条件まで深掘り
|
||||||
* @param obj ナビゲーションObject
|
* @param obj ナビゲーションObject
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ExtIco from 'bi/box-arrow-up-right.svg';
|
import ExtIco from 'bi/box-arrow-up-right.svg';
|
||||||
import { $URL, isRelative, joinURL } from 'ufo';
|
import { $URL, isRelative, joinURL } from 'ufo';
|
||||||
|
import { isLocalPath, sanitizeInternalPath } from '@/assets/js/misc';
|
||||||
|
|
||||||
const runtimeConfig = useRuntimeConfig();
|
const runtimeConfig = useRuntimeConfig();
|
||||||
const rootDomain = new $URL(runtimeConfig.public.baseUrl);
|
const rootDomain = new $URL(runtimeConfig.public.baseUrl);
|
||||||
@ -23,12 +24,12 @@ const realHref = ref(props.href);
|
|||||||
const realTarget = ref(props.target);
|
const realTarget = ref(props.target);
|
||||||
|
|
||||||
const url = new $URL(realHref.value);
|
const url = new $URL(realHref.value);
|
||||||
if (url.host === '' || rootDomain.host === url.host) {
|
if (isLocalPath(realHref.value)) {
|
||||||
// 内部リンクの場合
|
// 内部リンクの場合
|
||||||
const route = resolve(realHref.value);
|
const route = resolve(realHref.value);
|
||||||
if (route.name && !route.name.toString().includes('___')) {
|
if (route.name && !route.name.toString().includes('___')) {
|
||||||
// 渡されたパスがローカライズされたルートではない場合はローカライズされたパスを返す
|
// 渡されたパスがローカライズされたルートではない場合はローカライズされたパスを返す
|
||||||
realHref.value = localePath(url.fullpath);
|
realHref.value = sanitizeInternalPath(localePath(url.fullpath));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 相対パスの場合(trailing slashがあるので1つくり下げる)
|
// 相対パスの場合(trailing slashがあるので1つくり下げる)
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { cleanDoubleSlashes, withTrailingSlash } from 'ufo';
|
import { cleanDoubleSlashes, withTrailingSlash } from 'ufo';
|
||||||
import { isLocalPath } from '@/assets/js/misc';
|
import { isLocalPath, sanitizeInternalPath } from '@/assets/js/misc';
|
||||||
import type { RouteLocationRaw } from '#vue-router';
|
import type { RouteLocationRaw } from '#vue-router';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +29,7 @@ const realHref = computed(() => {
|
|||||||
if (rhf && typeof rhf === 'string') {
|
if (rhf && typeof rhf === 'string') {
|
||||||
|
|
||||||
if (isLocalPath(rhf)) {
|
if (isLocalPath(rhf)) {
|
||||||
return withTrailingSlash(cleanDoubleSlashes(rhf), true);
|
return withTrailingSlash(cleanDoubleSlashes(sanitizeInternalPath(rhf)), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rhf;
|
return rhf;
|
||||||
|
@ -8,8 +8,19 @@ useHead({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
const { data: navigation } = await useAsyncData(`navigation_${locale.value}`, () => fetchContentNavigation(queryContent(`/${locale.value}/docs/`)));
|
const navigation = ref();
|
||||||
|
const asideNavKey = ref(0);
|
||||||
|
const { data } = await useAsyncData(`navigation_${locale.value}`, () => fetchContentNavigation(queryContent(`/${locale.value}/docs/`)));
|
||||||
|
navigation.value = data.value;
|
||||||
|
|
||||||
|
watch(locale, async (to) => {
|
||||||
|
console.log('locale changed');
|
||||||
|
const { data } = await useAsyncData(`navigation_${to}`, () => fetchContentNavigation(queryContent(`/${to}/docs/`)));
|
||||||
|
navigation.value = data.value;
|
||||||
|
asideNavKey.value++;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -22,7 +33,7 @@ const { data: navigation } = await useAsyncData(`navigation_${locale.value}`, ()
|
|||||||
:class="isAsideNavOpen ? 'translate-x-0' : '-translate-x-64'"
|
:class="isAsideNavOpen ? 'translate-x-0' : '-translate-x-64'"
|
||||||
>
|
>
|
||||||
<div class="lg:sticky lg:top-16 h-[calc(100vh-7.25rem)] lg:h-[calc(100vh-4rem)] overflow-y-scroll border-r border-slate-200 dark:border-slate-700 py-6 pr-3">
|
<div class="lg:sticky lg:top-16 h-[calc(100vh-7.25rem)] lg:h-[calc(100vh-4rem)] overflow-y-scroll border-r border-slate-200 dark:border-slate-700 py-6 pr-3">
|
||||||
<DocsAsideNav :links="navigation ?? []" />
|
<DocsAsideNav :links="navigation ?? []" :key="asideNavKey" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
|
@ -29,9 +29,9 @@ export const locales = localesConst as unknown as LocaleObject[];
|
|||||||
|
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
locales,
|
|
||||||
public: {
|
public: {
|
||||||
baseUrl,
|
baseUrl,
|
||||||
|
locales,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
css: [
|
css: [
|
||||||
|
@ -14,7 +14,7 @@ export default defineNitroPlugin((nitroApp) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const runtimeConfig: MiHubRuntimeConfig = useRuntimeConfig();
|
const runtimeConfig: MiHubRuntimeConfig = useRuntimeConfig();
|
||||||
if (!event.path.match(new RegExp(`^/(${runtimeConfig.locales.map((l) => l.code).join('|')})/`))) {
|
if (!event.path.match(new RegExp(`^/(${runtimeConfig.public.locales.map((l) => l.code).join('|')})/`))) {
|
||||||
const links = runtimeConfig.locales.map((l) => {
|
const links = runtimeConfig.locales.map((l) => {
|
||||||
const url = withTrailingSlash(`/${l.code}${event.path.replace(/\.html$/g, '/')}`);
|
const url = withTrailingSlash(`/${l.code}${event.path.replace(/\.html$/g, '/')}`);
|
||||||
return `<a href="${url}">${l.name}</a>`;
|
return `<a href="${url}">${l.name}</a>`;
|
||||||
|
Loading…
Reference in New Issue
Block a user