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

@@ -9,18 +9,15 @@ import { getUrl } from "@/modules/atproto/getUrl"
import { withATProtoImages } from "@/modules/atproto/withATProtoImages" import { withATProtoImages } from "@/modules/atproto/withATProtoImages"
import { getAuthor } from "@/modules/atproto/getAuthor" import { getAuthor } from "@/modules/atproto/getAuthor"
import { PublicNoteRecord } from "@/modules/atproto/publicNote.types" import { PublicNoteRecord } from "@/modules/atproto/publicNote.types"
import { parseAtUri } from "@/modules/atproto/parseAtUri"
const props = defineProps<{ const props = defineProps<{
atUri: string didrkey: string
index: number index: number
title?: string
}>() }>()
const atUri = computed(() => props.atUri) const didrkey = computed(() => props.didrkey)
const atUriProps = computed(() => parseAtUri(atUri.value)) const did = computed(() => props.didrkey.split("-")[0])
const did = computed(() => atUriProps.value.did) const rkey = computed(() => props.didrkey.split("-")[1])
const rkey = computed(() => atUriProps.value.rkey)
const index = computed(() => props.index) const index = computed(() => props.index)
@@ -33,7 +30,7 @@ const className = computed(() => `stacked-note-${props.index}`)
const titleClassName = computed(() => `title-${className.value}`) const titleClassName = computed(() => `title-${className.value}`)
const { scrollToFocusedNote } = useRouteQueryStackedNotes() const { scrollToFocusedNote } = useRouteQueryStackedNotes()
const { listenToClick } = useATProtoLinks(className.value, atUri) const { listenToClick } = useATProtoLinks(className.value, didrkey)
const { displayNoteOverlay } = useNoteOverlay(className.value, index) const { displayNoteOverlay } = useNoteOverlay(className.value, index)
const noteRecord = computedAsync(async () => const noteRecord = computedAsync(async () =>
@@ -70,12 +67,12 @@ watch(
:class="{ :class="{
[className]: true, [className]: true,
overlay: displayNoteOverlay, overlay: displayNoteOverlay,
[`note-${rkey}`]: true, [`note-${didrkey}`]: true,
}" }"
> >
<a <a
class="title-stacked-note-link" class="title-stacked-note-link"
@click.prevent="scrollToFocusedNote(rkey)" @click.prevent="scrollToFocusedNote(didrkey)"
> >
<div <div
class="title-stacked-note breadcrumbs text-sm" class="title-stacked-note breadcrumbs text-sm"

View File

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

View File

@@ -1,4 +1,5 @@
export const LINKS = ['http://', 'https://'] export const LINKS = ["http://", "https://"]
export const isExternalLink = (href: string) => export const isExternalLink = (href: string) =>
!href.startsWith(window.location.origin) &&
LINKS.some((link) => href.startsWith(link)) LINKS.some((link) => href.startsWith(link))

View File

@@ -133,7 +133,7 @@ watch(
:key="stackedNote" :key="stackedNote"
class="note" class="note"
:index="index" :index="index"
:at-uri="stackedNote" :didrkey="stackedNote"
/> />
</div> </div>
</template> </template>