Skip to content

fix(nav-order): respect navigation order for notes using path rewrite rules - #378

Merged
oleeskild merged 1 commit into
mainfrom
fix/nav-order-rewrite-rules
Jun 5, 2026
Merged

oleeskild merged 1 commit into
mainfrom
fix/nav-order-rewrite-rules

Conversation

@oleeskild

Copy link
Copy Markdown
Owner

Problem

Fixes #786 — navigation order is silently ignored for any note affected by a path rewrite rule, even after re-checking and re-saving the order in the plugin.

Root cause

When a path rewrite rule applies, the plugin writes a dg-path into the published frontmatter that includes the .md extension (e.g. Path Rewriting/note.md → dg-path: note.md).

getPermalinkMeta in filetreeUtils.js built the file-tree leaf key with folders[last] += ".md", assuming dg-path had no extension (true for manually-set dg-path and for filePathStem, which Eleventy strips). For rewrite-rule notes this produced a double extension: note.md.md.

The stored navigationOrder uses stems (note), and sortTree's resolver only tries note / note.md. The note.md.md key never matched, so the note dropped to default sort and the custom order was lost. This is why the bug only appears with rewrite rules.

Fix

Strip a trailing .md before re-appending it, so leaf keys are always single-extension regardless of whether dg-path carried the extension. Only .md is stripped (not arbitrary dots), so names like my-note-v1.2 are preserved.

Also in this change:

  • Declared the implicit globals in assignNested (previously only worked in CommonJS sloppy mode; threw under strict/ESM and leaked globals).
  • Converted filetreeUtils.test.js to ESM imports so it actually runs under vitest run (it was using jest-style globals and not running in the suite).

Tests

Added 3 tests covering the rewrite-rule scenario (root, nested folder, and dot-in-name). Confirmed they fail before the fix (note.md.md keys) and pass after.

Test Files  6 passed (6)
     Tests  223 passed (223)

🤖 Generated with Claude Code

Path rewrite rules produce a dg-path in the published frontmatter that
already includes the ".md" extension (e.g. "Path Rewriting/note.md" ->
dg-path "note.md"). getPermalinkMeta appended ".md" unconditionally,
yielding a double extension ("note.md.md") for the file-tree leaf key.

The stored navigationOrder uses stems ("note"), and sortTree's resolver
only tries "note" / "note.md" — so the double-extension key never
matched and the custom order was silently dropped to default sort.

Strip a trailing ".md" before re-appending it so leaf keys are always
single-extension, regardless of whether dg-path carried the extension.
Note names containing other dots (e.g. "my-note-v1.2") are preserved.

Also declare the implicit globals in assignNested (only worked in
CommonJS sloppy mode) and convert filetreeUtils.test.js to ESM imports
so it actually runs under `vitest run`.

Fixes #786

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@oleeskild
oleeskild merged commit 773ed1b into main Jun 5, 2026
1 check passed
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