From a55b98e07ac9e42a2f82effa1002102a20f09f5d Mon Sep 17 00:00:00 2001 From: Peaceultime Date: Wed, 10 Jan 2024 00:09:43 +0100 Subject: [PATCH] Add empty link security --- components/content/prose/ProseA.vue | 109 ++++++++++++++-------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/components/content/prose/ProseA.vue b/components/content/prose/ProseA.vue index 72cde57..9867e1d 100644 --- a/components/content/prose/ProseA.vue +++ b/components/content/prose/ProseA.vue @@ -34,38 +34,36 @@ 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(), loading = ref(true); -queryContent().where({ _path: new RegExp("/" + sluggify(link) + '$', 'i') }).findOne().then((result: ParsedContentExtended) => { - content.value = result; - loading.value = false; - let body = result.body; +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) - { - body = body as MarkdownRoot; - const id = flatten(body?.toc?.links ?? []).find(e => "#" + sluggify(e.id) === anchor); - const tag = `h${id?.depth ?? 0}`; + 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}`; - const startIdx = body.children.findIndex(e => e.tag === tag && e?.props?.id === id?.id) ?? 0; - const nbr = body.children.findIndex((e, i) => i > startIdx && e.tag?.match(new RegExp(`h[1-${id?.depth ?? 1}]`))); + const startIdx = body.children.findIndex(e => e.tag === tag && e?.props?.id === id?.id) ?? 0; + const nbr = body.children.findIndex((e, i) => i > startIdx && e.tag?.match(new RegExp(`h[1-${id?.depth ?? 1}]`))); - 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') { + body = body as CanvasContent; + const nodes = body?.groups?.find(e => "#" + sluggify(e.name) === anchor)?.nodes; + + body.nodes = body.nodes.filter(e => nodes?.includes(e.id)); + body.edges = body.edges.filter(e => nodes?.includes(e.fromNode) && nodes?.includes(e.toNode)); + } } - else if(result._type == 'canvas') - { - body = body as CanvasContent; - const nodes = body?.groups?.find(e => "#" + sluggify(e.name) === anchor)?.nodes; - - body.nodes = body.nodes.filter(e => nodes?.includes(e.id)); - 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); -}); + }).catch(() => { + loading.value = false; + }); +} const hovered = ref(false), pos = ref(); let timeout: NodeJS.Timeout; @@ -94,36 +92,39 @@ function hidePreview(e: Event) { \ No newline at end of file