docsify icon indicating copy to clipboard operation
docsify copied to clipboard

relative paths of links in sidebar should be relative to the sidebar file

Open ruanqizhen opened this issue 3 years ago • 14 comments

Bug Report

The relative path should always based on the file that quote it.

For example, the path (foo) in file bar.md should always point to the foo.md file that in the same folder of bar.md.
But the current mechanism of relative path is based on the current url. That means if the current url is in folder xxxx, the (foo) in file bar.md file will point to the foo.md in folder xxxx.
That means the relative will never work if you have a sidebar with multiple layer of documents.

I hope this could be fixed in the next docsify version.

Other relevant information

  • [ ] Bug does still occur when all/other plugins are disabled?

  • Your OS:

  • Node.js version:

  • npm/yarn version:

  • Browser version:

  • Docsify version:

  • Docsify plugins:

Please create a reproducible sandbox

Edit 307qqv236

Mention the docsify version in which this bug was not present (if any)

ruanqizhen avatar Dec 07 '21 22:12 ruanqizhen

Hello @ruanqizhen What you described seems to be what the doc says:

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

Can you make a reproduction?

trusktr avatar Dec 07 '21 22:12 trusktr

Hello @ruanqizhen What you described seems to be what the doc says:

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

Can you make a reproduction?

The current implementation only consider a single base path for relative paths.
My point is that when there are 2 md files loaded, one sidebar, and one content md, the relative paths in the sidebar md and the content may need different base paths: relative path in the sidebar md should always base on the sidebar md path; the relative path in the the content md should always base on the content md path.

ruanqizhen avatar Dec 07 '21 23:12 ruanqizhen

Just use the case in the document:

.
└── docs
    ├── README.md
    ├── guide.md
    └── zh-cn
        ├── README.md
        ├── guide.md
        └── config
            └── example.md

Suppose there is a single sidebar file for all the md files listed here, with the current relative path mechanism, there is not way to make the links in sidebar point to the right files.

ruanqizhen avatar Dec 07 '21 23:12 ruanqizhen

Found a workaround: I'm using absolute path in sidebar file, and using relative paths in other files now.

ruanqizhen avatar Dec 08 '21 03:12 ruanqizhen

I see what you're saying: yeah, links in sidebar should be relative to the sidebar file. That would be most intuitive.

When this is implemented, we need to think if it needs to be behind an option so as not to break existing apps.

trusktr avatar Dec 08 '21 05:12 trusktr

I am also very interested in this functionality. In my use case I have a top-level "portal" docsify site that brings in several other project docsify sites as subfolders. Each of the projects has their own _sidebar. But when used in the portal, the links in the project sidebars no longer work because it's using the main top-level folder instead of looking relative to the folder containing the sidebar.

mike-potter avatar Jan 11 '22 16:01 mike-potter

It's possible that using relativePath: true helps with this, if all of the sub-projects are also configured for this.

mike-potter avatar Jan 11 '22 16:01 mike-potter

Nope, that doesn't work either. If the projects have subfolders, then once a page in the subfolder is loaded, the other pages in the sidebar no longer work as they use the new subfolder as the relative path. So still can't find a way to basically embed one docsify site within another.

I agree with the OP that the links in the sidebar should be relative to the location of the _sidebar file. Using relativePath just makes them relative to the current path, which changes once you are in a subfolder.

mike-potter avatar Jan 11 '22 16:01 mike-potter

Yeah, it's a bit counterintuitive right now.

For backwards compat, I believe we need a new option for this (false by default). It will override relativePath for the sidebar.

Perhaps named like sidebarLinksRelativeToSidebarFile? Any other naming ideas?

The docs need more clarity here too.

trusktr avatar Jan 12 '22 03:01 trusktr

Closed https://github.com/docsifyjs/docsify/issues/1139 in favor of this one.

cc @CxRes (since you were interested in trying to solve it with that code mod you made in the other issue, open to a PR)

trusktr avatar Jan 12 '22 05:01 trusktr

How about relativeSidebarPaths?

hexus avatar Jan 12 '22 15:01 hexus

Is there any approximate ETA on this or plugin that could be tried to get the functionality in the meantime?

This will make multi-lingual and multi version libraries very much easier to create, and remove the limitations where you're forced to have your content for translations in different repositories.

Or to put it another way, I have my docs structured like this.

/en/*
/zh/*

And I have different versions stored as branches in same repo. I want to access the paths using aliases. e.g. main/en/*.*, v12/zh/*.*

If the sidebar links were relative to the sidebar then this would work for versions, translations, whatever, because the context would be relative to the imported root.

As it is this can't work unless every summary has the full language and version path specified absolutely. Yuck.

hamishwillee avatar Aug 24 '22 23:08 hamishwillee

I am also very interested in this functionality. In my use case I have a top-level "portal" docsify site that brings in several other project docsify sites as subfolders. Each of the projects has their own _sidebar. But when used in the portal, the links in the project sidebars no longer work because it's using the main top-level folder instead of looking relative to the folder containing the sidebar.

Is this fixed? When I read the official documentation, I also found that the subdirectory uses an absolute path, which is very awkward!! Like what

https://github.com/docsifyjs/docs-zh/edit/master/_sidebar.md [快速开始](zh-cn/quickstart.md) it can't work in your own warehouse ;

page 404 https://github.com/docsifyjs/docs-zh/blob/master/zh-cn/quickstart.md

https://github.com/docsifyjs/docsify/edit/develop/docs/_sidebar.md - [Quick start](quickstart.md)

chenGit1763113879QQ avatar Feb 10 '23 17:02 chenGit1763113879QQ

@chenGit1763113879QQ Not as far as I know. The workaround I use (not in production) is described here: https://evilmartians.com/chronicles/easy-multi-language-multi-version-documentation-with-docsify-git-and-github-actions

hamishwillee avatar Feb 12 '23 21:02 hamishwillee

Bug acknowledged. Tracking with #1891.

jhildenbiddle avatar Mar 02 '24 04:03 jhildenbiddle