question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When `relativePath: true`, relative path links in _sidebar do not resolve reasonably

See original GitHub issue

Bug 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
  1. Run the server
  2. Browse to http://localhost:3000/#/
  3. Click Subdir1
  4. 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dellagustin-sapcommented, Apr 25, 2020

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?

0reactions
StoneyJacksoncommented, Apr 27, 2020

Sorry I never got around to this 😦

Glad to see others are working on it though!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative path in HTML - Stack Overflow
I want to make all of link resources in my website to relative path ( I mean only internal resources). website is located...
Read more >
Absolute vs. Relative Paths/Links - CoffeeCup Software
In the example above, we used a relative path. You can tell if a link is relative if the path isn't a full...
Read more >
Relative vs Absolute Paths - linking continued - iLoveCoding
The URLs which are relative to a particular location, are called relative paths. The links which are directly going to a particular location...
Read more >
Enhance the xref macro to permit relative document references
We've eliminated the relative path (../../) problem by specifying the page as a module-relative path. The path always starts from a module's ...
Read more >
Relative and absolute paths, in the file system and on the web ...
If you don't supply the root, it means that your path is relative. The simplest example of relative path is just a file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found