MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / resolveMarkdownOpenTarget

Function resolveMarkdownOpenTarget

apps/desktop/src/main/file-open.ts:38–56  ·  view source on GitHub ↗
(
  absPath: string,
  knownVaultRoots: readonly string[]
)

Source from the content-addressed store, hash-verified

36 * external file when it lives outside every known vault.
37 */
38export function resolveMarkdownOpenTarget(
39 absPath: string,
40 knownVaultRoots: readonly string[]
41): MarkdownOpenTarget {
42 const target = path.resolve(absPath)
43 let best: { root: string; rel: string } | null = null
44 for (const candidate of knownVaultRoots) {
45 const rel = vaultRelativeNotePath(candidate, target)
46 if (!rel) continue
47 const resolvedRoot = path.resolve(candidate)
48 // Prefer the deepest matching vault so a note inside a nested vault
49 // opens against that vault rather than an ancestor.
50 if (!best || resolvedRoot.length > best.root.length) {
51 best = { root: resolvedRoot, rel }
52 }
53 }
54 if (best) return { kind: 'vault', vaultRoot: best.root, relPath: best.rel }
55 return { kind: 'external', absPath: target }
56}
57
58/**
59 * Pull candidate markdown file paths out of a process argv array. Used

Callers 2

file-open.test.tsFile · 0.90
openMarkdownFileFromOSFunction · 0.90

Calls 1

vaultRelativeNotePathFunction · 0.85

Tested by

no test coverage detected