Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some links try to load invalid files #101

Open
wischi-chr opened this issue Feb 21, 2023 · 3 comments
Open

Some links try to load invalid files #101

wischi-chr opened this issue Feb 21, 2023 · 3 comments

Comments

@wischi-chr
Copy link

My markdown files already have relative links because most of the time when I'm editing them I'm using VS Code and similar tools. If I click on links that reference another markdown file the extension will be added twice and the page fails to load.

for example if I have a link like this [Some random text](OtherFile.md) it will generate a URL that ends with /OtherFile.md but that page than tries to load /OtherFile.md.md

Other cases would be files that seem to be supported but are not .md files, for example like .txt and .ini. Those files are listed (on the /list pages) but when I click them the URL is generated without the extension and than the page tries to load an .md file that doesn't exist.

My guess is that originally one wanted to keep the wiki URLs clean and without extensions but that seems to break in a lot of cases.

At this point I think there would be two options to solve those issues:

  1. Always just use the original filename including extension in the URL. This would be simple and straight forward but the URLs would be a bit less clean.
  2. Another solution would be to change the way files are looked up. First check the URL if it already points to a valid file and if not try other extensions. So if I open /Folder/PageA test if there really is a file without extension and open that. If there is not try to append ".md" and test if that file exists. This would allow for clean URLs but fix the issues mentioned above.

I like Option 1 better and it would be the least surprising to users, but I guess there was a reason to drop the ".md" from the URLs in the first place.

@Linbreux
Copy link
Owner

Hi @wischi-chr thanks for the detailed review. I guess we could use option 1. I don't think there is a reason why we don't use the .md extension.

We could switch to that, although we should allow backward compatibility. Some users will have links referring to a file in the wiki like:

somefile links to somefile.md

So we could navigate to the link. If there is no file, try to remove suffix (like option2).

@johann-petrak
Copy link

I just tried showing an image from the local directory or embedding a link to a local directory or local .txt file in a page and nothing of this seems to work because all those files are accessed with an added .md extension.

I think it would be good to allow for a list of extensions where the (local) URL is not modified and instead the file is served in the standard way. So for example if a link to an image is in a wiki file, then clicking that link would just let the browser view that file. There are actually two ways to do this:

  • since we know the location of the file on the local file system, the link in the markdown file could get replaced by the corresponding absolute file:///wherever/it/is/stored.png URL
  • wikmd reads the file and serves it using the correct mime type but that would be a lot more effort and would, I think not have any advantages over the first option

@johann-petrak
Copy link

Actually, what I said in the previous comment is wrong as modern browsers will not allow to link from a http(s)://localhost URL to a file:/// URL any more.

So the only way to supprot this would be to recognize specific file extensions as media files and serve them with the proper mime type using the correct localhost URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants