mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-22 08:53:49 +01:00
47 lines
1.1 KiB
Vue
47 lines
1.1 KiB
Vue
<script setup lang="ts">
|
|
import ExtIco from 'bi/box-arrow-up-right.svg';
|
|
|
|
const runtimeConfig = useRuntimeConfig();
|
|
const rootDomain = new URL(runtimeConfig.public.baseUrl);
|
|
const localePath = useLocalePath();
|
|
|
|
const props = defineProps({
|
|
href: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
target: {
|
|
type: String,
|
|
default: undefined,
|
|
required: false
|
|
},
|
|
})
|
|
|
|
let realHref = props.href;
|
|
let realTarget = props.target;
|
|
|
|
try {
|
|
const url = new URL(props.href);
|
|
if (!url.hostname || rootDomain.hostname === url.hostname) {
|
|
realHref = localePath(realHref);
|
|
}
|
|
|
|
if (rootDomain.hostname !== url.hostname) {
|
|
realTarget = '_blank';
|
|
}
|
|
} catch(_) {
|
|
if(realHref !== '') {
|
|
if (!realHref.startsWith('.') || !realHref.startsWith('http')) {
|
|
realHref = localePath(realHref);
|
|
} else {
|
|
realHref = '../' + realHref;
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<GNuxtLink :href="realHref" :target="realTarget">
|
|
<slot></slot><ExtIco v-if="realTarget === '_blank'" class="text-xs mx-1" />
|
|
</GNuxtLink>
|
|
</template> |