You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
when using relativePath: true, links on the sidebar are always relative to the current page #1139
It has no access to current file for the sidebar (I suppose this is also true for the navbar).
The only place where this information is available seems to be:
I could not think of an easy solution.
There are many layers between where the information is available and where it is used.
I have considered the following:
Modiy loadNested also pass down the current path to the next callback (maybe as a 3rd parameter, or enriching the section parameter, as it is a dictionary.
Pass the current path to _renderSidebar and _renderNav
Extend the HashHistory router to return the current path (of sidebar or navbar) on getCurrentPath
Instatiate a different compiler to use for redering sidebar and navbar, that would use as router the new extended HashHistory
I did not check yet how to create automated tests for this.
If I am not wrong, when you are in subpage1 (absolute) , you click on the subpage1 (relative) and its searching for the page in that directory instead of from root . right ?
if this is, then its the intended behavior as sidebar is always at root (of the current folder) so the base path will be the current path. if you want to go up one directory in order to render that page you need to give related path from where the sidebar is.
If I am not wrong, when you are in subpage1 (absolute) , you click on the subpage1 (relative) and its searching for the page in that directory instead of from root . right ?
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.
I think I can solve this issue. My strategy is to pass a isParent property to the next function in loadNested if it is invoked a second time which is passed to _renderSidebar and then compiler.sidebar. Now ideally I should be able to ask the compiler to append '../' to each link or I can mutate paths from _sidebar.md to append '../'.
functionloadNested(path,qs,file,next,vm,first){path=first ? path : path.replace(/\/$/,'');path=getParentPath(path);if(!path){return;}get(vm.router.getFile(path+file)+qs,false,vm.config.requestHeaders).then(next,function(_){returnloadNested(path,qs,file,(r)=>next(r,true),vm);});}...varfn=function(result,isParent){this$1._renderSidebar(result,isParent);cb();};// Load sidebarloadNested(path,qs,loadSidebar,fn,this$1,true);proto._renderSidebar=function(text,isParent){
...
this._renderTo('.sidebar-nav',that.compiler.sidebar(result,maxLevel,isParent));
...
}Compiler.prototype.sidebar=functionsidebar(text,level,isParent){
...
if(text){html=this.compile(text,isParent&&{baseUrl: '../'});// using this to modify marked.setOptions}
...
An alternative could be to pass the path from loadNested and use it to build absolute urls before passing it to the compiler.
But I have a couple of questions:
How do I ask marked to append ../ to links. Adding baseUrl does not seem to work.
How do I get a handle to relativePath in compiler.sidebar.
I'm having this issue as well. Another workaround is to make the paths in _sidebar.md absolute. The problem is that then the file is not usable independently of docsify; e.g. if you view it in GitHub the links will not resolve correctly. Also you can't use markdown-link-check on the file for the same reason—this is perhaps a bigger problem. I maintain a substantial piece of documentation and rely on markdown-link-check to keep it working.
I too have been bitten by this. This will be officially solved in #1684 with a new option (for backwards compatibility, so that existing options like relativePath work the same).
Activity
dellagustin commentedon Apr 26, 2020
I have considered whether this behavior was intended to cover some specific scenario, but could not think of any in which it would be beneficial.
I have browsed the code, the link rendered uses the current route to resolve relative links:
docsify/src/core/render/compiler/link.js
Line 20 in b2e6123
It has no access to current file for the sidebar (I suppose this is also true for the navbar).
The only place where this information is available seems to be:
docsify/src/core/fetch/index.js
Line 8 in b2e6123
I could not think of an easy solution.
There are many layers between where the information is available and where it is used.
I have considered the following:
loadNestedalso pass down the current path to the next callback (maybe as a 3rd parameter, or enriching the section parameter, as it is a dictionary.HashHistoryrouter to return the current path (of sidebar or navbar) ongetCurrentPathHashHistoryI did not check yet how to create automated tests for this.
anikethsaha commentedon Apr 26, 2020
Thanks for the detailed issue. 💯
If I am not wrong, when you are in
subpage1 (absolute), you click on thesubpage1 (relative)and its searching for the page in that directory instead of from root . right ?if this is, then its the intended behavior as sidebar is always at root (of the current folder) so the base path will be the current path. if you want to go up one directory in order to render that page you need to give related path from where the sidebar is.
dellagustin commentedon Apr 26, 2020
Hi @anikethsaha
Right, if I understood that correctly.
To give more details:
In my example, if you are at https://dellagustin-sap.github.io/docsify-relative-path-bug-report/#/subpages/subpage1 (route is
/subpages/subpage1, you will get here from/by clicking either the absolute or relative link), and then you click in the relative link, it will link to https://dellagustin-sap.github.io/docsify-relative-path-bug-report/#/subpages/subpages/subpage1Now, in my example the sidebar markdown file is always at root (not of the current folder, but https://dellagustin-sap.github.io/docsify-relative-path-bug-report/sidebar.md) - and that is why I think that the links on the sidebar should be resolved relative to where the sidebar file was found.
About:
I am not sure what you mean with always here, because
loadNestedwill recursively search for the sidebar up the path structure: https://docsify.js.org/#/more-pages?id=nested-sidebarsanikethsaha commentedon Apr 26, 2020
loadNested? did you meanloadSidebarsorry, I thought you had the aliases setup to fallback to root.
this needs investigation. I will check once again.
cc @docsifyjs/reviewers , thoughts ?
dellagustin commentedon Apr 26, 2020
No actually meant this function:
docsify/src/core/fetch/index.js
Line 8 in b2e6123
anikethsaha commentedon Apr 26, 2020
ok cool, I will check that soon for sure 👍 .
stale commentedon Jun 25, 2020
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.
CxRes commentedon Aug 4, 2020
I think I can solve this issue. My strategy is to pass a
isParentproperty to thenextfunction inloadNestedif it is invoked a second time which is passed to_renderSidebarand thencompiler.sidebar. Now ideally I should be able to ask the compiler to append '../' to each link or I can mutate paths from _sidebar.md to append '../'.An alternative could be to pass the
pathfromloadNestedand use it to build absolute urls before passing it to the compiler.But I have a couple of questions:
../to links. AddingbaseUrldoes not seem to work.relativePathincompiler.sidebar.sy-records commentedon Aug 4, 2020
I tried it and I don't think it's a problem.
no get 404
The two files in your sidebar should both use absolute paths.
MrBlenny commentedon Sep 2, 2021
I was having this issue but was able to resolve it for now by writing the
_sidebar.mdin html instead of markdown.i.e.
becomes:
note,
#is added and.mdis removed.brandones commentedon Oct 7, 2021
I'm having this issue as well. Another workaround is to make the paths in
_sidebar.mdabsolute. The problem is that then the file is not usable independently of docsify; e.g. if you view it in GitHub the links will not resolve correctly. Also you can't use markdown-link-check on the file for the same reason—this is perhaps a bigger problem. I maintain a substantial piece of documentation and rely on markdown-link-check to keep it working.trusktr commentedon Jan 12, 2022
I too have been bitten by this. This will be officially solved in #1684 with a new option (for backwards compatibility, so that existing options like
relativePathwork the same).