jointrashposs/components/content/ProseA.vue

41 lines
953 B
Vue
Raw Normal View History

2023-07-11 19:19:32 +02:00
<script setup lang="ts">
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 !== '') {
realHref = localePath(realHref);
}
}
</script>
<template>
<GNuxtLink :href="realHref" :target="realTarget">
2023-07-12 15:51:05 +02:00
<slot></slot><GIcon :icon="'box-arrow-up-right'" v-if="realTarget === '_blank'" class="text-xs mx-1" />
2023-07-11 19:19:32 +02:00
</GNuxtLink>
</template>