danodic-dev / mkdocs-backlinks

A plugin for adding backlinks to mkdocs.
MIT License
15 stars 2 forks source link

Doesn't work with a folder structure #3

Closed ZbindenDaniel closed 1 year ago

ZbindenDaniel commented 1 year ago

Hello there!

I really like this plugin. It helps me visualizing relations inbetween documents. I work with folders to have an internal structure. The issue I'm facing now is that files that are not in the '/doc' (e.g. root folder) don't seem to be included in the build step of this plugin.

For example if I have files strucutred like this:

File1 does get the backlinks but file 2 does not.

Am I using it wrong? Do I have to tweek some settings?

Greetings Daniel

danodic commented 1 year ago

Hello Daniel,

It is supposed to get the backlinks in the structure you described. Here is an example of how I have setup my personal page: https://github.com/danodic-dev/danodicdev-digital-garden

Here is the configuration file: https://github.com/danodic-dev/danodicdev-digital-garden/blob/main/mkdocs.yml

Please let me know if your project follows the same structure.

I appreciate If you could please provide a sample of File1.md and File2.md, it may help on debugging the issue.

Thanks.

ZbindenDaniel commented 1 year ago

Hey

Sorry for the late reply. I didn't get around to respond. I checked out your digital garden and it seemed to me that the backlinks as I intend to use them are also not working there.

My file structure looks as follows (Similar to yours):

/docs

Now, if I link from a file in one folder to a file in another, the link doesn't get recognised. I tried to visualize the linkage by arrows:

flowchart LR
    subgraph docs
    index;
    xy
    subgraph a
    a1;a2;a3;a4;

    a1-->a2
    end

    subgraph b
    b1;b2;b3
    b1-->b2
    b1 --> a1
    end

    subgraph c
    c1;c2;
    c1-->c2
    c1 --> a4
    b3 --> c1
    end
end

For example; the link from b1 to a1 is not considered in the build step as it goes from one subfolder to another.

I'll have a look at your plugin any maybe come up with a solution.

saludos Daniel

ZbindenDaniel commented 1 year ago

I found something the helped me. You normalize the links very nicely but some still contain backslashes ('\'). Afterward they cannot be found in the the dictionary you have. This appears to be happening in my scenario with the subfolders.

As a quick fix I just appended replace('\', '/') to your normalize_link() method [line 74]

destination_link = self.__normalize_link(href, page.url).replace('\\', '/')

have a nice day

danodic commented 1 year ago

Thanks for the heads up.

It makes sense, as I have developed and tested in Linux where the slashes are all /.

I'll add this fix to it, thanks!