docsifyjs / docsify

🃏 A magical documentation site generator.
https://docsify.js.org
MIT License
27.66k stars 5.68k forks source link

Embedded files doesn't resolve relative links #865

Closed aenniw closed 4 years ago

aenniw commented 5 years ago

Bug Report

Docsify doesn't resolve relative links in embedded markdown files correctly. Whenever MD file contains any relative link instead of file content user just gets Not found 404 error.

Steps to reproduce

README.md

[Task](./task/README.md ':include')

task/README.md

# Crossword:

On the last page you found a weird crossword puzzle. Perhaps it reveals a flag for you.

[crosswords.png](./crosswords.png ':ignore')

task/crosswords.png

What is current behaviour

Link to crosswords.png points to /crosswords.png

What is the expected behaviour

Link to crosswords.png should point to /task/crosswords.png

Other relevant information

filipgoc commented 5 years ago

I second the problem. This makes embeds useless unless everything is plain text with no media.

Is this a bug or a limitation?

Is there a way to handle this with aliases in the index file? (I tried, but unsuccessfully.)

filipgoc commented 5 years ago

This is a duplicate of the very old https://github.com/docsifyjs/docsify/issues/695, but this issue contains more info and a formatted example.

filipgoc commented 5 years ago

This really messes up my workflow. If anyone has any ideas for a workaround (not even thinking of a fix, just a hack), please. Any suggestions welcome!

filipgoc commented 5 years ago

Ok I have a workaround. Phew. It's NOT a fix, but it makes it workable; with a bit of manual work.

Add relative symlinks to all the relevant directories and files.

In the most simple case, let's say I have assets folder where all the images are stored.

I can add a symlink to this folder with the same name, and the relative links resolve correctly (through the symlink).

I have tested it and it works.

Feel free to ping me if you're trying the same thing and have issues.

Tip: I also discovered I needed to add an empty <span></span> at the end of every markdown file that has an :include, otherwise my footer does not work properly (my footer is created as a plugin in the index.html...)

As in

Some paragraph. 

[filename](include.md ':include')

<span></span>
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

dellagustin-sap commented 4 years ago

Hello, we have this issue as well in our website based on docsify, please keep it open until #867 is either merged or closed.

dellagustin-sap commented 4 years ago

I believe this issue is still happening, we are currently using docsify 4.11.3, I need to create a dedicated example.

anikethsaha commented 4 years ago

create a separate issue if it still exists with sandbox example.

Thanks

dellagustin-sap commented 4 years ago

That's the plan 😉

dellagustin-sap commented 4 years ago

I actually found out that in order to have the behaviour I wanted, I had to set option relativePath to true.

https://docsify.js.org/#/configuration?id=relativepath

There is a side effect though, the sidebar links become relative to the current path. This can be solved (or worked around) by making the sidebar links absolute.

I could not find whether this is by design or if it is a bug, should I report it as an issue? I have a repository demonstrating it: https://dellagustin-sap.github.io/docsify-relative-path-bug-report/#/

dellagustin-sap commented 4 years ago

I found out that the behavior I reported in the previous comment related to relative paths and the sidebar was already reported here: https://github.com/docsifyjs/docsify/issues/925