When `relativePath: true`, relative path links in _sidebar do not resolve reasonably
See original GitHub issueBug Report
First, let me say, I’m loving Docsify! Great stuff! 👍
Now on to my issue…
When using both loadSidebar:true
and relativePath:true
relative paths in _sidebar.md files are resolved against the page being rendered rather than the location of the _sidebar.md file. This leads to surprising results. When one writes a relative path in a file, one expects it to be relative to that file, not some other file that implicitly includes it in some subdirectory.
The work around is to only use absolute paths in _sidebar.md files since they may be rendered in arbitrarily nested subdirectories. The problem with this is that it makes it difficult to move an entire subdirectory that contains a _sidebar.md, and it requires authors to know and encode the full path to their subsite.
I am in an environment where we pull documentation from multiple projects and integrate them into one website. I don’t want authors to encode the full path to their project’s documentation in the main site. This creates an unnecessary dependency, making it challenging to reorganize the structure of the combined site, and it also places additional burden on authors to know the path of their subsite.
So I’m hoping that it’s possible to resolve relative URLs in _sidebar.md files against the location of the _sidebar.md file. 🤞
Steps to reproduce
GIVEN
$ tree
.
├── README.md
├── _sidebar.md
├── index.html
├── subdir1
│ └── README.md
└── subdir2
└── README.md
2 directories, 5 files
$ cat _sidebar.md
- [Home](README.md)
- [Subdir1](subdir1/README.md)
- [Subdir2](subdir2/README.md)
$ cat index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LibreFoodPantry</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
loadSidebar: true,
relativePath: true,
};
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
</body>
</html>
$
WHEN
- Run the server
- Browse to http://localhost:3000/#/
- Click Subdir1
- Click Subdir2
What is current behaviour
Get a 404
What is the expected behaviour
Display Subdir2
Other relevant information
-
Bug does still occur when all/other plugins are disabled?
-
Your OS: MacOS
-
Node.js version: v12.9.1
-
npm/yarn version: 1.17.3
-
Browser version: Google Chrome 77.0.3865.90 (Official Build) (64-bit)
-
Docsify version: Latest from unpkg.com (see index.html)
-
Docsify plugins: None
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top GitHub Comments
I recently found out this very same behavior. I was going to report it to ask if it is working as designed or if this is a bug.
In my opinion, with respect to sidebar, it is a bug, as I could not imagine any commonly used scenario where this behaviour would be desireable.
@anikethsaha, do you see any supported scenario that would break if the links from sidebar, when relative, would be always relative to the file location, instead of relative to the location of the file used to generate the current page?
Sorry I never got around to this 😦
Glad to see others are working on it though!