Skip to content

Auto-sync .note files to markdown, with mirror/watch folders - #120

Draft
philips-clanker wants to merge 1 commit into
mainfrom
auto-sync-markdown-export
Draft

Auto-sync .note files to markdown, with mirror/watch folders#120
philips-clanker wants to merge 1 commit into
mainfrom
auto-sync-markdown-export

Conversation

@philips-clanker

Copy link
Copy Markdown
Collaborator

Summary

Split out of #81 (by @Floper), rebased onto current main. This is the auto-sync + mirror/watch-folder piece; it has no dependency on the other pieces of #81.

  • New opt-in auto-sync: when a .note file is created or modified in the vault (e.g. by a mobile sync tool), automatically write/update its markdown export.
    • modify events are debounced (2s) since a sync can fire several in quick succession for one file.
    • Handles the race where Obsidian fires both create and modify for the same sync: falls back from vault.create to vault.modify if the file already exists by the time we write.
  • Watched folder setting: scope auto-sync to one vault folder instead of the whole vault.
  • Markdown mirror folder setting: save exported .md files into a separate folder that mirrors the .note structure, instead of alongside each .note file. ensureFolderExists creates missing intermediate folders.
  • Bug fix: writeMarkdownFile's path construction used `${file.parent?.path}/${file.basename}.md`, which produces //name.md for vault-root files (Obsidian returns "/" as the root folder path). Now derived from file.path directly.

Ported onto the current settings.ts declarative-settings API and the current VaultWriter shape (main has diverged substantially from #81's base).

Test plan

  • npm run build (tsc + esbuild) - clean
  • npx eslint src/main.ts src/settings.ts - 0 errors
  • npx vitest run - 22 passed
  • Manual test in Obsidian: enable auto-sync, drop/modify a .note file, confirm .md export appears/updates; test watched-folder and mirror-folder settings together and independently

Adds an opt-in auto-sync: when a .note file is created or modified in
the vault (e.g. by a mobile sync tool), its markdown export is written
or updated automatically, optionally scoped to a watched folder and/or
mirrored into a separate folder instead of sitting alongside the .note
file.

Along the way, fixes writeMarkdownFile's path construction, which used
`${file.parent?.path}/${file.basename}.md` - for vault-root files
Obsidian returns "/" as the parent path, producing a "//name.md"
double-slash bug. The path is now derived from file.path directly.

Split out of #81 (by @Floper), ported onto the current settings.ts
declarative API and current main.ts VaultWriter shape.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant