( absPath: string, knownVaultRoots: readonly string[] )
| 36 | * external file when it lives outside every known vault. |
| 37 | */ |
| 38 | export 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 |
no test coverage detected