Files
ar9av__obsidian-wiki/probe2.py
Amir Fathi f268d43744 fix(lint): stop flagging embeds and normalise .md/escaped-pipe wikilink targets (#204)
* fix(lint): stop flagging embeds and normalise .md/escaped-pipe wikilink targets

broken_links harvests every [[wikilink]] target, including embeds
(![[diagram.png]], [[board.canvas]], [[dashboard.base]]) that by_slug can
never hold since _iter_pages globs only *.md. An explicit .md suffix
([[alpha.md]]) and a table-escaped pipe ([[beta\|B]]) were also compared
raw against the slugged index instead of being normalised the way
_normalise_node_id already normalises a page's own id, so both never
resolved either.

_wikilink_page_target() returns None for a non-.md-extension target
(skipping attachment embeds) and otherwise strips an explicit .md suffix
and a trailing backslash before _parse_page slugs it. On the issue's own
repro vault this drops broken_links from 7 flagged (6 false positives) to
the one genuinely broken link.

Fixes #176

* fix(lint): only skip attachment extensions, not every dotted page name

Path("Node.js").suffix is ".js", so the previous `if suffix: return None`
dropped links to any page whose name contains a dot. Those links feed orphan
detection and link_count as well as broken_links, so "Node.js", "Next.js",
"v1.2 release notes" and friends were reported as orphans.

Skip only Obsidian's attachment extensions instead.

---------

Co-authored-by: ar9av <ar9avg@gmail.com>
2026-09-03 04:09:35 -07:00

18 lines
868 B
Python

import sys, tempfile, pathlib
sys.path.insert(0, ".")
from obsidian_wiki.lint import lint_vault
def page(v, rel, links=()):
p = v / rel; p.parent.mkdir(parents=True, exist_ok=True)
p.write_text("---\ntitle: T\ncategory: concepts\ntags: [a]\nsources: []\n"
"created: 2026-01-01\nupdated: 2026-01-01\nsummary: s\n---\n\n"
+ "\n".join(f"- [[{l}]]" for l in links) + "\n", encoding="utf-8")
for name, link in [("Node.js", "Node.js"), ("Next.js", "Next.js"),
("v1.2 release notes", "v1.2 release notes"),
("GPT-4.1 eval", "GPT-4.1 eval"), ("plain", "plain")]:
v = pathlib.Path(tempfile.mkdtemp()) / "vault"
page(v, f"entities/{name}.md"); page(v, "concepts/index.md", links=[link])
r = lint_vault(v)
print(f"{name:22} links={r['stats']['link_count']} orphans={r['findings']['orphan_pages']}")