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) : '';
|
const anchor = props.href.includes('#') ? props.href.substring(props.href.indexOf('#'), props.href.length) : '';
|
||||||
let content = ref<ParsedContentExtended>(), loading = ref(true);
|
let content = ref<ParsedContentExtended>(), loading = ref(true);
|
||||||
|
|
||||||
queryContent().where({ _path: new RegExp("/" + sluggify(link) + '$', 'i') }).findOne().then((result: ParsedContentExtended) => {
|
if(props.href !== '')
|
||||||
|
{
|
||||||
|
queryContent().where({ _path: new RegExp("/" + sluggify(link) + '$', 'i') }).findOne().then((result: ParsedContentExtended) => {
|
||||||
content.value = result;
|
content.value = result;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
let body = result.body;
|
let body = result.body;
|
||||||
|
|
||||||
if(anchor && result && body)
|
if (anchor && result && body) {
|
||||||
{
|
if (result._type == 'markdown' && (body as MarkdownRoot).children) {
|
||||||
if(result._type == 'markdown' && (body as MarkdownRoot).children)
|
|
||||||
{
|
|
||||||
body = body as MarkdownRoot;
|
body = body as MarkdownRoot;
|
||||||
const id = flatten(body?.toc?.links ?? []).find(e => "#" + sluggify(e.id) === anchor);
|
const id = flatten(body?.toc?.links ?? []).find(e => "#" + sluggify(e.id) === anchor);
|
||||||
const tag = `h${id?.depth ?? 0}`;
|
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);
|
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;
|
body = body as CanvasContent;
|
||||||
const nodes = body?.groups?.find(e => "#" + sluggify(e.name) === anchor)?.nodes;
|
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));
|
body.edges = body.edges.filter(e => nodes?.includes(e.fromNode) && nodes?.includes(e.toNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.error("Found ", props.href);
|
}).catch(() => {
|
||||||
}).catch(() => {
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
console.error("Cannot find ", props.href);
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
const hovered = ref(false), pos = ref<any>();
|
const hovered = ref(false), pos = ref<any>();
|
||||||
let timeout: NodeJS.Timeout;
|
let timeout: NodeJS.Timeout;
|
||||||
|
|
@ -94,7 +92,8 @@ function hidePreview(e: Event) {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template >
|
<template >
|
||||||
<NuxtLink custom no-prefetch v-slot="{ href: hrefSlot, navigate }" :href="{path: content?._path ?? link, hash: anchor}" :target="target">
|
<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>
|
<a :href="hrefSlot" @click="navigate" @mouseenter="(e) => showPreview(e, true)" @mouseleave="hidePreview" v-bind="$attrs"><slot ></slot></a>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<Teleport to="body" v-if="hovered && (loading || !!content)">
|
<Teleport to="body" v-if="hovered && (loading || !!content)">
|
||||||
|
|
@ -126,4 +125,6 @@ function hidePreview(e: Event) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
<a v-bind="$attrs" v-else><slot></slot></a>
|
||||||
</template>
|
</template>
|
||||||
Loading…
Reference in New Issue