(fix) Docsで相対パスが使えない

fix #95
This commit is contained in:
kakkokari-gtyih 2023-12-30 13:16:36 +09:00
parent be1497cc3f
commit 6a6a149ff2

View File

@ -1,11 +1,11 @@
<script setup lang="ts">
import MiIco from '@/assets/svg/misskey_mi_bi.svg';
import ExtIco from 'bi/box-arrow-up-right.svg';
import { $URL, isRelative, joinURL } from 'ufo';
import { parseURL, isRelative, joinURL } from 'ufo';
import { isLocalPath, sanitizeInternalPath } from '@/assets/js/misc';
const runtimeConfig = useRuntimeConfig();
const rootDomain = new $URL(runtimeConfig.public.baseUrl);
const rootDomain = parseURL(runtimeConfig.public.baseUrl);
const { resolve } = useRouter();
const localePath = useGLocalePath();
@ -24,20 +24,20 @@ const props = defineProps({
const realHref = ref(props.href);
const realTarget = ref(props.target);
const url = new $URL(realHref.value);
const url = parseURL(realHref.value);
if (isLocalPath(realHref.value)) {
//
if (/^\/[a-z]{2}\//.test(realHref.value)) {
realHref.value = sanitizeInternalPath(url.fullpath);
} else {
//
realHref.value = sanitizeInternalPath(localePath(url.fullpath));
}
// trailing slash
if (isRelative(realHref.value)) {
realHref.value = joinURL('../', realHref.value);
realHref.value = joinURL('../', realHref.value.replace(/^\.\//, ''));
}
//
if (/^\/[a-z]{2}\//.test(realHref.value)) {
realHref.value = sanitizeInternalPath(realHref.value);
} else {
//
realHref.value = sanitizeInternalPath(localePath(resolve(realHref.value).fullPath));
}
} else if (rootDomain.host !== url.host) {
realTarget.value = '_blank';