From 44f5663f50105b4d1efe728c6eed0a61c2eb47de Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sat, 14 Feb 2026 02:00:54 +0100 Subject: [PATCH] feat: add font customization --- src/bus/publicNoteEventBus.ts | 8 ++++ src/hooks/useATProtoLinks.hook.ts | 74 +++++++++++++++++++++++++++++++ src/modules/atproto/getAka.ts | 2 - src/views/PublicNoteListView.vue | 2 + src/views/PublicNoteView.vue | 43 +++++++++++++++--- 5 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 src/bus/publicNoteEventBus.ts create mode 100644 src/hooks/useATProtoLinks.hook.ts diff --git a/src/bus/publicNoteEventBus.ts b/src/bus/publicNoteEventBus.ts new file mode 100644 index 0000000..341842b --- /dev/null +++ b/src/bus/publicNoteEventBus.ts @@ -0,0 +1,8 @@ +import { createEventBus } from "retrobus" + +interface EventBusParams { + path: string + currentNoteRkey?: string +} + +export const publicNoteEventBus = createEventBus() diff --git a/src/hooks/useATProtoLinks.hook.ts b/src/hooks/useATProtoLinks.hook.ts new file mode 100644 index 0000000..87baa09 --- /dev/null +++ b/src/hooks/useATProtoLinks.hook.ts @@ -0,0 +1,74 @@ +import { ComputedRef, onUnmounted, Ref, toValue } from "vue" + +import { isExternalLink } from "@/utils/link" +import { publicNoteEventBus } from "@/bus/publicNoteEventBus" + +export const useATProtoLinks = ( + className: ComputedRef | string, + rkey?: Ref | string, +) => { + const linkNote: EventListener = (event) => { + const target = event.target as HTMLElement + const href = target.getAttribute("href") + + if (!href) { + return + } + + if (href.startsWith("#")) { + return + } + + event.preventDefault() + event.stopPropagation() + + if (isExternalLink(href)) { + window.open(href, "_blank") + return + } + + publicNoteEventBus.emit({ + path: href, + currentNoteRkey: toValue(rkey), + }) + } + + const LINK_SELECTOR = `.${toValue(className)} a` + + const removeListeners = () => { + const elements = document.querySelectorAll(LINK_SELECTOR) + + elements.forEach((element) => { + element.removeEventListener("click", linkNote) + }) + } + + const listenToClick = () => { + removeListeners() + const elements = document.querySelectorAll(LINK_SELECTOR) + + elements.forEach((element) => { + const href = element.getAttribute("href") + + if (!href) { + return + } + + if (isExternalLink(href)) { + element.classList.add("external-link") + } + }) + + elements.forEach((element) => { + element.addEventListener("click", linkNote) + }) + } + + onUnmounted(() => { + removeListeners() + }) + + return { + listenToClick, + } +} diff --git a/src/modules/atproto/getAka.ts b/src/modules/atproto/getAka.ts index dfa21f4..7c92769 100644 --- a/src/modules/atproto/getAka.ts +++ b/src/modules/atproto/getAka.ts @@ -3,7 +3,6 @@ type Author = { alias: string; endpoint: string } const correspondanceCache = new Map() export const getUniqueAka = async (did: string): Promise => { - console.log(correspondanceCache) if (correspondanceCache.has(did)) { return correspondanceCache.get(did) as Author } @@ -18,7 +17,6 @@ export const getUniqueAka = async (did: string): Promise => { const author = { alias, endpoint: serviceEndpoint } correspondanceCache.set(did, author) - console.log(correspondanceCache) return author } diff --git a/src/views/PublicNoteListView.vue b/src/views/PublicNoteListView.vue index b368f18..2cfbe2c 100644 --- a/src/views/PublicNoteListView.vue +++ b/src/views/PublicNoteListView.vue @@ -106,6 +106,8 @@ const getAlias = (did: string) => aka.value.get(did) ?? "" .alias { text-align: right; + display: flex; + justify-content: flex-end; } } } diff --git a/src/views/PublicNoteView.vue b/src/views/PublicNoteView.vue index c018e0a..8af249b 100644 --- a/src/views/PublicNoteView.vue +++ b/src/views/PublicNoteView.vue @@ -1,10 +1,12 @@