-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Support sidebarAbsolutePath to fix relative link and nested sidebar when I just provide one sidebar.md #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the CI error
@anikethsaha I’m sorry, I did not find the way to fix. Could you please have a look to this problem? |
its because you added a header add |
Fixed. Thanks! |
I will review this soon |
|
||
// auto alias sidebar which is set to be absolute path | ||
if (config.sidebarAbsolutePath) { | ||
const sidebar = config.loadSidebar || '_sidebar.md'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this sidebarAbsolutePath
option? Or can we just provide an absolute path in loadSidebar
? We can use a url tool to detect absolute path, like /path/to/sidebar.md
, //path/to/sidebar.md
, https://example.com/path/to/sidebar.md
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think about this: what happend if they set sidebarAbsolutePath
to true, but it isn't an absolute path? Should it be an error? Will they be confused?
Here's an idea on how to detect absolute paths with a regex: https://stackoverflow.com/a/19709846/454780 (but we should allow paths starting with /
to return true if we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an idea on how to detect absolute paths with a regex: https://stackoverflow.com/a/19709846/454780 (but we should allow paths starting with
/
to return true if we want.
Yes, we should consider detecting too.
It should works with `loadSidebar`. If you do not set `loadSidebar`, don't set this option any more. | ||
|
||
It works well with `relativePath` and `basePath`. You do not need to worry about the path conflict. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs don't describe what the option actually does. It doesn't mention that it can be a string. Can you please update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @trusktr. There also seems to be some gramma thats not correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good idea. But we need some changes:
- just use one variable for this if possible,
loadSidebar
, and detect all absolute paths. Is there a reason not to use one option for this case? - Make sure the docs describe the option in full. At the moment it is not clear what to do with the option, it doesn't mention anything about the string values.
thanks @trusktr for the detailed review. |
I will create a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on this, this is a feature that some users could defiantly use.. There is a few things i would suggest changed.
You've rearranged some imports that I don't think it necessary. The less files that is changed in a PR the easier it is to be get reviewed. I would suggest that you reverted the files that only has import changes to the previous state.
It should works with `loadSidebar`. If you do not set `loadSidebar`, don't set this option any more. | ||
|
||
It works well with `relativePath` and `basePath`. You do not need to worry about the path conflict. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @trusktr. There also seems to be some gramma thats not correct
@@ -1,13 +1,13 @@ | |||
import { readFileSync } from 'fs'; | |||
import { resolve, basename } from 'path'; | |||
import resolvePathname from 'resolve-pathname'; | |||
import fetch from 'node-fetch'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be reverted to the previous state. There is no point in rearranging imports if this is the only changes in the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a result of the automated husky lint process, which modifies the files. The git commit
step should not leave modifications in the working tree.
!config.ignore | ||
) { | ||
if (href === compilerClass.config.homepage) { | ||
const sidebarAbsolutePath = compiler.config.sidebarAbsolutePath; | ||
const basePath = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me the following lines has a weird formatting.
I would suggest doing this instead:
const basePath = | |
const basePath = typeof sidebarAbsolutePath === 'string' | |
? sidebarAbsolutePath | |
: router.getBasePath(); | |
const relativeTo = isSidebar && sidebarAbsolutePath | |
? basePath | |
: router.getCurrentPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tangshuang for this idea!
We should make a function called isAbsolute
, and we can use this along with out new isExternal
function: if the condition isExternal(url) || isAbsolute(url)
is true, we can automatically treat the URL the same way as proposed in this PR, but without having to have a new sidebarAbsolutePath
option.
The more combinations of options we need to have, the more difficult it is for the user to understand and easier to get it wrong.
just to add a point, this will be a part of v5 cause I dont think we can do any feature or enhancement release as of now, it all should be released with v5 if this gets approved.
I believe for non-breaking changes we can release them in v4.x until we're ready for v5.
You've rearranged some imports that I don't think it necessary. The less files that is changed in a PR the easier it is to be get reviewed. I would suggest that you reverted the files that only has import changes to the previous state.
I agree with this in general, though as I mentioned in the other comment it is a result of the automated commit hook. EDIT: a recent fix automatically commits the changes (see #1108). Once things are in good shape, this won't happen anymore. We should make the automated tests fail for any such changes, to make them required (otherwise, let's remove the automated changes from the commit hook).
@anikethsaha @arelstone Let's take on this pull request ourselves unless @tangshuang will return to make the changes before we do.
Summary
What kind of change does this PR introduce? (check at least one)
If changing the UI of default theme, please provide the before/after screenshot:
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
fix #xxx[,#xxx]
, where "xxx" is the issue number)You have tested in the following browsers: (Providing a detailed version will be better.)
If adding a new feature, the PR's description includes:
To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.
Other information:
Referer to issues:
relativePath: true
, relative path links in _sidebar do not resolve reasonably #925lib
directory.