import { basename, dirname, join } from '../filesystem/vaultFs'; import type { OpenDocRequest } from '../workspaces/workspace'; /** The open document a link is being followed *from*. */ export type LinkSource = { /** Provider the current document belongs to. */ providerId: string; /** The current document's id/path (links resolve relative to its folder). */ path: string; }; /** * Resolve a relative markdown link target (e.g. `Note.md`, `sub/Note.md`) * against the document it was clicked in, producing an `OpenDocRequest` the * workspace can open. Resolution is a plain path join relative to the source * document's folder — callers pass external (scheme-bearing) targets elsewhere. */ export function resolveDocumentLink( source: LinkSource, target: string, ): OpenDocRequest { const entryId = join(dirname(source.path), target); return { providerId: source.providerId, entryId, title: basename(entryId) }; }