Skip to content

Enhancement: Reconcile nav tree hierarchy with Notion (reparent, nav_changed) #75

Description

@virtualguard101

Summary

Notion sync pushes content for nav-listed markdown files but does not keep the nav directory tree aligned with the Notion page hierarchy after reorganization. Users who change .nav.yml (move sections, change parents) get stale or wrong structure on Notion while local notes remain correct.

Problem

Scenario Current behavior
Nav-only change (markdown unchanged) nav_changed is detected in git diff but never used
Change parent in nav Content update only; page is not reparented in Notion
New intermediate section Depends on ensure_section (see related bug for Notebook 404)

Incremental sync only targets md_changed / assets_changed / full — structure is ignored unless content also changed.

Motivation

Nav is the source of truth for wiki layout. Notion should mirror that tree, not evolve independently.

Proposed solution

Add a structure reconciliation phase (default on, or --align-structure):

  1. Walk the nav tree and ensure section pages exist (create missing sections).
  2. For each nav-listed content page with a known Notion ID, compare nav parent vs actual Notion parent; move the page when they differ (Notion move API).
  3. When nav_changed is true (even without markdown diffs), run reconciliation for the affected subtree or full tree.
  4. Support --align-structure --no-content for hierarchy-only runs.

CLI sketch

mkdocs-note ns                          # content + align (proposed default)
mkdocs-note ns --align-structure --no-content
mkdocs-note ns --dry-run --align-structure

Optional mkdocs.yml:

notion_sync:
  align_structure: true

Acceptance criteria

  • Moving a page to another nav section reparents the existing Notion page (no duplicate).
  • .nav.yml changes alone trigger structure reconciliation.
  • Dry-run lists planned create_section and reparent actions.
  • Summary includes counts: sections_created, reparented, etc.
  • --align-structure false preserves current content-only behavior.

Out of scope (separate issues)

  • Archiving orphans (--prune)
  • Git rename state migration
  • Syncing nav title changes to Notion page titles

References

  • run_sync, collect_targets, ensure_section in mkdocs_note/utils/notion/sync.py
  • TreeNode.parent_key in mkdocs_note/utils/tree.py

Related

  • Bug: Notebook ensure_section parent_kind (blocks new sections under Notebook)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions