hunyadi / md2conf

Publish Markdown files to Confluence wiki
MIT License
56 stars 31 forks source link

external links to anchor in another markdown file in same repository #54

Closed golharam closed 1 month ago

golharam commented 2 months ago

I have a README.md that contains a link to another markdown file within the same repo:

[Link to other file](OTHER_FILE.md)

The OTHER_FILE.md is part of the same repo. I've added a confluence-page-id, confluence-space-key tag to the top of that markdown and already published it to Confluence. Now, when I try to publish my README.md, I get the error: m2conf.converter.DocumentError: unable to find matching page for URL: OTHER_FILE.md

How do you handle links like this?

golharam commented 2 months ago

I see in sample/example.md: Relative links to other pages are also supported if you are synchronizing a directory tree, not a single file.

Maybe this is the solution? If I want to publish the README.md and all markdown files it is associated with?

hunyadi commented 2 months ago

Today, you should synchronize a directory tree to tackle this scenario. md2conf is currently implemented to take two passes: first, it scans a directory hierarchy to extract metadata; second, it generates XHTML (Confluence Storage Format) for the documents it has found. Relative links to other documents are resolved with the help of the metadata index created in the first phase. If you are converting a single document, no index is used.

In a future version, we may implement a reference graph in which outbound links are traversed, and documents with no inbound links are skipped. Currently, no such reference graph is built, and all documents in a directory hierarchy are discovered recursively, and published.

Entropy0 commented 1 month ago

There seems to be a regression here: In version 0.2.1 links worked as expected but with the currently released version we receive the error mentioned by OP even though we are synchronizing the whole directory which contains both files.

hunyadi commented 1 month ago

This recent issue seems to be confined to the use case when you pass a relative directory as an argument to process or synchronize, e.g. ./dir/file.md or dir/file.md. I could not reproduce the issue if I used absolute paths, e.g. /home/path/to/dir/file.md or /home/path/to/dir. I have added a call to path = path.resolve(True) to convert relative paths to absolute paths at all entry points. Let me know if you still encounter the issue even after you pull the commit Fix an issue with relative paths as arguments.