Skip to content

feat(export): add --with-sources to wire Obsidian notes to source content (#1968)#1973

Open
SinghAman21 wants to merge 1 commit into
Graphify-Labs:v8from
SinghAman21:fix/1968-obsidian-with-sources
Open

feat(export): add --with-sources to wire Obsidian notes to source content (#1968)#1973
SinghAman21 wants to merge 1 commit into
Graphify-Labs:v8from
SinghAman21:fix/1968-obsidian-with-sources

Conversation

@SinghAman21

Copy link
Copy Markdown
Contributor

Wire Obsidian node notes to their source content (--with-sources) — #1968

Why

Right now every note in an exported Obsidian vault is a bare stub: frontmatter, the H1 title, and a ## Connections list of wikilinks. The source_file field exists in frontmatter but it's just a dead string — it doesn't link to anything. So anyone browsing the vault (or an agent hopping between notes) has to leave the vault entirely to learn what a node actually is. The graph structure is great, but the notes carry no substance.

Users were working around this with a post-processing script that copies sources in and rewires every note — but the exporter overwrites the notes on each re-export, so they had to re-run the script every single time.

What

A new opt-in flag on the Obsidian export:

graphify export obsidian --with-sources

With it, the vault becomes usable standalone:

  • Every distinct source_file is copied into the vault under sources/ as a real note (src.md).
  • Each node note gets a callout right under its title linking to that source:
  • Optional --source-root PATH to override where source paths are resolved from disk.

How

  • graphify/export.py — to_obsidian gains with_sources / source_root params plus four small helpers:
    • resolve each source_file (stored relative to the scan root) to a real file on disk;
    • flatten nested/Windows paths into one collision-safe note name;
    • copy markdown/text verbatim, and embed code/other files in a syntax-highlighted fence;
    • write one deduped note per distinct source, then insert the callout after each node's H1.
  • graphify/cli.py — parses the two new flags and defaults resolution to [scan root, out dir] (the out-dir fallback keeps older pre-0.9.17 graphs working).

Behavior chosen deliberately:

  • Source notes are graphify-owned, so the existing manifest/prune logic cleans them up automatically — a re-export without the flag removes them and the vault returns to plain notes.
  • A node whose source can't be found on disk (or exceeds a 2 MB cap) simply gets no callout rather than a dangling link.
  • Nodes sharing a source_file all link to the same single source note.

Conclusion

This solves the issue's core ask — turn source_file into a resolvable link and bring source content into the vault — without any manual post-processing. It's fully opt-in, so default exports are unchanged, and it plays cleanly with the existing re-export/prune machinery. Covered by a new test file (tests/test_obsidian_with_sources.py, 5 tests) with the existing export suite (91 tests) still green.

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