44 lines
1.6 KiB
Vue
44 lines
1.6 KiB
Vue
<template>
|
|
<NuxtLink class="preview-link" v-if="data && data[0] && status !== 'pending'"
|
|
:to="{ path: `/explorer/${project}/${data[0].path}`, hash: hash }" :class="class">
|
|
<PreviewContent :project="project" :path="data[0].path" :anchor="hash">
|
|
<slot v-bind="$attrs"></slot>
|
|
<ThemeIcon class="link-icon" v-if="data && data[0] && data[0].type !== 'Markdown'" :height="20" :width="20"
|
|
:icon="`link-${data[0].type.toLowerCase()}`" />
|
|
</PreviewContent>
|
|
</NuxtLink>
|
|
<NuxtLink v-else-if="href" :to="href" :class="class">
|
|
<slot v-bind="$attrs"></slot>
|
|
<ThemeIcon class="link-icon" v-if="data && data[0] && data[0].type !== 'Markdown'" :height="20" :width="20"
|
|
:icon="`link-${data[0].type.toLowerCase()}`" />
|
|
</NuxtLink>
|
|
<slot :class="class" v-else v-bind="$attrs"></slot>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { parseURL } from 'ufo';
|
|
|
|
const props = defineProps({
|
|
href: {
|
|
type: String,
|
|
required: false,
|
|
},
|
|
class: {
|
|
type: String,
|
|
required: false,
|
|
}
|
|
});
|
|
|
|
const route = useRoute();
|
|
const { hash, pathname, protocol } = parseURL(props.href);
|
|
const project = computed(() => parseInt(Array.isArray(route.params.projectId) ? '0' : route.params.projectId));
|
|
const { data, status } = await useFetch(`/api/project/${project.value}/file`, {
|
|
method: 'GET',
|
|
query: {
|
|
search: `%${pathname}`
|
|
},
|
|
transform: (data) => data?.map(e => ({ path: e.path, type: e.type })),
|
|
key: `file:${project.value}:%${pathname}`,
|
|
dedupe: 'defer'
|
|
});
|
|
</script> |