jonathan-s/pelican-obsidian

Bug when running on windows

Opened this issue · 3 comments

When running on windows, there is an issue with the formatting and how it interacts with pelican formatting. The first indication of this issue was the URLS were showing up like this: http://127.0.0.1:8000/%7Bfilename%7D/reference/Databricks/Databricks Tables.md

In the section of code where the paths are assigned and built:

filename, linkname = get_file_and_linkname(match)
path = ARTICLE_PATHS.get(filename)
if path:
link_structure = '[{linkname}]({{filename}}{path}{filename}.md)'.format(
linkname=linkname, path=path, filename=filename
)

I added some debug line to see what was going on.

Path: \reference\Databricks/
Filename: Databricks Tables
Fullpath: \reference\Databricks/Databricks Tables
Replaced Link:[Databricks Tables]({filename}\reference\Databricks/Databricks Tables.md)

I suspected that the two slashes - back and forward slash - were causing issues. After going in and manually putting links in markdown files it was discovered that ANY backslashes do not work correctly.

Doesn't work: [Databricks Tables]({filename}\reference\Databricks\Databricks Tables.md)
Doesn't work: [Databricks Tables]({filename}\reference\Databricks/Databricks Tables.md)
Does work: [Databricks Tables]({filename}/reference/Databricks/Databricks Tables.md)

Because of this behavior, I think that this issue is actually with how Pelican parses links - it jsut doesn't work with Windows style links

Solution:
Replace all separators with forward slashes regardless of operating system:

link_structure = link_structure.replace(os.sep, '/')

I plan on making a PR for this soon, but this is a temporary work around until then.

Thank you, since I'm not running windows, I won't be able to check this. Happy to accept a PR for it though.

Though rather than doing str.replace, it might be better to use pathlib.Path to build up the path first and then get the string version of that.

@acherrera FYI I have solved this by using vscode + devcontainer in my Windows machine for now.

  • Use obsidian as Markdown Editor
  • Use vscode + devcontainer for build and publish.