orbikm / mkdocs-ezlinks-plugin

Plugin for mkdocs which enables easier linking between pages
MIT License
34 stars 17 forks source link

[FR] Ambiguities & indexes : use metadata title to prevent it #41

Closed Mara-Li closed 2 years ago

Mara-Li commented 2 years ago

I use indexe.navigations (see here), and I think I have an idea to get the best result with index : using the frontmatter.

Use case / Problem

I use Obsidian (the best note taking app in the world, yes). I often make links with "index" files (cf navigation.indexes de Material). In fact, it will regularly happen that there will be several times files named Index.

A first solution would be to get the closest index file (in the same folder) but it is common for me to quote indexes present in other folders, without necessarily quoting the whole path (a script takes care of converting the wikilinks paths by replacing the name of the "real" file by the index)

In fact, citations can quickly point to bad links.

Solution

By using python-frontmatter, it becomes possible to find the metadata of the files. When an ambiguity is found, the file can be checked.

My idea would be to use, in these cases, the title field rather than the actual file title, with the title being indicated by the alias.

Finally, we use an "extra" indication in the wikilinks to point to the real file: [[index|yaml_title]] will thus point to the file whose title is the same as the one given in the yaml alias.

In case of an index with an alias that does not match any title, just take the closest one, i.e. using the current method.

Note: I'm not familiar with Mkdocs plugins yet, so I guess it's also possible to find the "yaml" titles of all files without going through the frontmatter.