Thanks to visit codestin.com
Credit goes to github.com

Skip to content

When relativePath: true, relative path links in _sidebar do not resolve reasonablyΒ #925

Closed
@StoneyJackson

Description

@StoneyJackson

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions