Links like `path/to/note.md#heading` previously errored with "Note not found" because the full href (including `#hash`) was matched against file paths. Split the fragment off in the link handler, plumb it through the event bus, and scroll the matching heading into view once the target note is in place. Headings now get GitHub-style ids via markdown-it-anchor + github-slugger so the anchors actually exist. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { computed, onUnmounted } from "vue"
|
|
|
|
import { noteEventBus } from "@/bus/noteEventBus"
|
|
import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook"
|
|
import { resolvePath } from "@/modules/repo/services/resolvePath"
|
|
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
|
|
import { pathToNotePathTitle } from "@/utils/noteTitle"
|
|
import { errorMessage } from "@/utils/notif"
|
|
|
|
export const useNoteView = () => {
|
|
const store = useUserRepoStore()
|
|
const { stackedNotes, addStackedNote } = useRouteQueryStackedNotes()
|
|
|
|
const titles = computed(() =>
|
|
stackedNotes.value?.reduce((obj: Record<string, string>, note) => {
|
|
if (!note) {
|
|
return obj
|
|
}
|
|
const filePath = store.files.find((file) => file.sha === note)?.path ?? ""
|
|
|
|
obj[note] = pathToNotePathTitle(filePath)
|
|
|
|
return obj
|
|
}, {})
|
|
)
|
|
|
|
const unsubscribeLink = noteEventBus.addEventBusListener(
|
|
({ path, hash, currentNoteSHA }) => {
|
|
const currentFile = store.files.find(
|
|
(file) => file.sha === currentNoteSHA
|
|
)
|
|
|
|
const absolutePath = resolvePath(currentFile?.path ?? "", path)
|
|
|
|
const file = store.files.find((file) => file.path === absolutePath)
|
|
if (!file?.sha) {
|
|
errorMessage(`Note ${absolutePath} not found.`)
|
|
return
|
|
}
|
|
|
|
addStackedNote(currentNoteSHA ?? "", file.sha, undefined, hash)
|
|
}
|
|
)
|
|
|
|
onUnmounted(() => {
|
|
unsubscribeLink()
|
|
})
|
|
|
|
return {
|
|
titles
|
|
}
|
|
}
|