feat: handle absolute internal links for stacked notes

This commit is contained in:
Julien Calixte
2026-02-19 21:32:37 +01:00
parent b14f5f1dc1
commit 801832c6e5
4 changed files with 42 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ import { ComputedRef, onUnmounted, Ref, toValue } from "vue"
import { isExternalLink } from "@/utils/link"
import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook"
import { parseAtUri } from "@/modules/atproto/parseAtUri"
import { router } from "@/router/router"
export const useATProtoLinks = (
className: ComputedRef<string> | string,
@@ -11,26 +12,50 @@ export const useATProtoLinks = (
const { addStackedNote } = useRouteQueryStackedNotes()
const linkNote = (event: Event) => {
const target = event.target as HTMLElement
const atUri = target.getAttribute("href")
const href = target.getAttribute("href")
if (!atUri) {
if (!href) {
return
}
if (atUri.startsWith("#")) {
if (href.startsWith("#")) {
return
}
event.preventDefault()
event.stopPropagation()
if (isExternalLink(atUri)) {
window.open(atUri, "_blank")
if (isExternalLink(href)) {
window.open(href, "_blank")
return
}
const { rkey } = parseAtUri(atUri)
addStackedNote(toValue(currentAtUri) ?? "", atUri, rkey)
if (href.startsWith(window.location.origin)) {
const { params } = router.resolve(
href.replace(window.location.origin, ""),
)
if (!params.did || !params.rkey) {
return
}
const noteId = params.slug
? `${params.did}-${params.rkey}-${params.slug}`
: `${params.did}-${params.rkey}`
addStackedNote(toValue(currentAtUri) ?? "", noteId)
return
}
if (href.startsWith("at://")) {
const { did, rkey } = parseAtUri(href)
addStackedNote(
toValue(currentAtUri) ?? "",
`${did}-${rkey}`,
`${did}-${rkey}`,
)
}
}
const LINK_SELECTOR = `.${toValue(className)} a`