Add empty link security
This commit is contained in:
parent
51e20b99c1
commit
a55b98e07a
|
|
@ -34,15 +34,15 @@ const link = (props.href.startsWith('/') ? '' : '/') + (props.href.includes('#')
|
|||
const anchor = props.href.includes('#') ? props.href.substring(props.href.indexOf('#'), props.href.length) : '';
|
||||
let content = ref<ParsedContentExtended>(), loading = ref(true);
|
||||
|
||||
if(props.href !== '')
|
||||
{
|
||||
queryContent().where({ _path: new RegExp("/" + sluggify(link) + '$', 'i') }).findOne().then((result: ParsedContentExtended) => {
|
||||
content.value = result;
|
||||
loading.value = false;
|
||||
let body = result.body;
|
||||
|
||||
if(anchor && result && body)
|
||||
{
|
||||
if(result._type == 'markdown' && (body as MarkdownRoot).children)
|
||||
{
|
||||
if (anchor && result && body) {
|
||||
if (result._type == 'markdown' && (body as MarkdownRoot).children) {
|
||||
body = body as MarkdownRoot;
|
||||
const id = flatten(body?.toc?.links ?? []).find(e => "#" + sluggify(e.id) === anchor);
|
||||
const tag = `h${id?.depth ?? 0}`;
|
||||
|
|
@ -52,8 +52,7 @@ queryContent().where({ _path: new RegExp("/" + sluggify(link) + '$', 'i') }).fin
|
|||
|
||||
body.children = body.children.splice(startIdx, (nbr === -1 ? body.children.length : nbr) - startIdx);
|
||||
}
|
||||
else if(result._type == 'canvas')
|
||||
{
|
||||
else if (result._type == 'canvas') {
|
||||
body = body as CanvasContent;
|
||||
const nodes = body?.groups?.find(e => "#" + sluggify(e.name) === anchor)?.nodes;
|
||||
|
||||
|
|
@ -61,11 +60,10 @@ queryContent().where({ _path: new RegExp("/" + sluggify(link) + '$', 'i') }).fin
|
|||
body.edges = body.edges.filter(e => nodes?.includes(e.fromNode) && nodes?.includes(e.toNode));
|
||||
}
|
||||
}
|
||||
console.error("Found ", props.href);
|
||||
}).catch(() => {
|
||||
loading.value = false;
|
||||
console.error("Cannot find ", props.href);
|
||||
});
|
||||
}
|
||||
|
||||
const hovered = ref(false), pos = ref<any>();
|
||||
let timeout: NodeJS.Timeout;
|
||||
|
|
@ -94,6 +92,7 @@ function hidePreview(e: Event) {
|
|||
</script>
|
||||
|
||||
<template >
|
||||
<template v-if="href !== ''">
|
||||
<NuxtLink custom no-prefetch v-slot="{ href: hrefSlot, navigate }" :href="{ path: content?._path ?? link, hash: anchor }" :target="target">
|
||||
<a :href="hrefSlot" @click="navigate" @mouseenter="(e) => showPreview(e, true)" @mouseleave="hidePreview" v-bind="$attrs"><slot ></slot></a>
|
||||
</NuxtLink>
|
||||
|
|
@ -127,3 +126,5 @@ function hidePreview(e: Event) {
|
|||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
<a v-bind="$attrs" v-else><slot></slot></a>
|
||||
</template>
|
||||
Loading…
Reference in New Issue