Something went wrong. Try again.
A local-first note taking app
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233import { 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 filesystem path; links resolve relative to its * folder. * * Must come from `OpenDocRequest.entryId`, NOT from `DocumentHandle.id`. * They coincide for a local vault, but a synced vault's handle id is an * `at://` URI (`syncedVaultDocumentsProvider` sets `id: session.uri`), and * taking `dirname` of that yields a target no provider can open. */ 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) };}