Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.8k
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?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
024d25785bec566db386b14a71d28aa6a106516b7633862c6File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import { readFileSync } from 'fs'; | ||
| import { resolve, basename } from 'path'; | ||
| import resolvePathname from 'resolve-pathname'; | ||
| import fetch from 'node-fetch'; | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| import debug from 'debug'; | ||
| import { AbstractHistory } from '../../src/core/router/history/abstract'; | ||
| import { Compiler } from '../../src/core/render/compiler'; | ||
| import { isAbsolutePath } from '../../src/core/router/util'; | ||
| import * as tpl from '../../src/core/render/tpl'; | ||
| import { prerenderEmbed } from '../../src/core/render/embed'; | ||
| import fetch from 'node-fetch'; | ||
| import debug from 'debug'; | ||
| function cwd(...args) { | ||
| return resolve(process.cwd(), ...args); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,23 +1,37 @@ | ||||||||||||||||
| import { getAndRemoveConfig } from '../utils'; | ||||||||||||||||
| import { isAbsolutePath } from '../../router/util'; | ||||||||||||||||
| export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) => | ||||||||||||||||
| (renderer.link = (href, title = '', text) => { | ||||||||||||||||
| export const linkCompiler = ({ | ||||||||||||||||
| renderer, | ||||||||||||||||
| router, | ||||||||||||||||
| linkTarget, | ||||||||||||||||
| compiler, | ||||||||||||||||
| isSidebar = false, | ||||||||||||||||
| }) => { | ||||||||||||||||
| const link = (href, title = '', text) => { | ||||||||||||||||
| let attrs = []; | ||||||||||||||||
| const { str, config } = getAndRemoveConfig(title); | ||||||||||||||||
| title = str; | ||||||||||||||||
| if ( | ||||||||||||||||
| !isAbsolutePath(href) && | ||||||||||||||||
| !compilerClass._matchNotCompileLink(href) && | ||||||||||||||||
| !compiler._matchNotCompileLink(href) && | ||||||||||||||||
| !config.ignore | ||||||||||||||||
| ) { | ||||||||||||||||
| if (href === compilerClass.config.homepage) { | ||||||||||||||||
| const sidebarAbsolutePath = compiler.config.sidebarAbsolutePath; | ||||||||||||||||
| const basePath = | ||||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Suggested change
| ||||||||||||||||
| typeof sidebarAbsolutePath === 'string' | ||||||||||||||||
| ? sidebarAbsolutePath | ||||||||||||||||
| : router.getBasePath(); | ||||||||||||||||
| const relativeTo = | ||||||||||||||||
| isSidebar && sidebarAbsolutePath ? basePath : router.getCurrentPath(); | ||||||||||||||||
| if (href === compiler.config.homepage) { | ||||||||||||||||
| href = 'README'; | ||||||||||||||||
| } | ||||||||||||||||
| href = router.toURL(href, null, router.getCurrentPath()); | ||||||||||||||||
| href = router.toURL(href, null, relativeTo); | ||||||||||||||||
| } else { | ||||||||||||||||
| if (!isAbsolutePath(href) && href.startsWith('./')) { | ||||||||||||||||
| href = | ||||||||||||||||
| @@ -48,4 +62,7 @@ export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) => | ||||||||||||||||
| } | ||||||||||||||||
| return `<a href="${href}" ${attrs.join(' ')}>${text}</a>`; | ||||||||||||||||
| }); | ||||||||||||||||
| }; | ||||||||||||||||
| renderer.link = link; | ||||||||||||||||
| return link; | ||||||||||||||||
| }; | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -42,8 +42,20 @@ export class History { | ||
| const { config } = this; | ||
| const base = this.getBasePath(); | ||
| const ext = typeof config.ext === 'string' ? config.ext : '.md'; | ||
| const alias = config.alias || {}; | ||
| const rules = Object.assign({}, alias); | ||
| // auto alias sidebar which is set to be absolute path | ||
| if (config.sidebarAbsolutePath) { | ||
| const sidebar = config.loadSidebar || '_sidebar.md'; | ||
| ||
| const base = | ||
| typeof config.sidebarAbsolutePath === 'string' | ||
| ? config.sidebarAbsolutePath | ||
| : this.getBasePath(); | ||
| rules['/.*/' + sidebar] = base + sidebar; | ||
| } | ||
| path = config.alias ? getAlias(path, config.alias) : path; | ||
| path = getAlias(path, rules); | ||
| path = getFileName(path, ext); | ||
| path = path === `/README${ext}` ? config.homepage || path : path; | ||
| path = isAbsolutePath(path) ? path : getPath(base, path); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,8 +2,8 @@ | ||
| require = require('esm')( | ||
| module /* , options */ | ||
| ); /* eslint-disable-line no-global-assign */ | ||
| const { resolvePath } = require('../../src/core/router/util'); | ||
| const { expect } = require('chai'); | ||
| const { resolvePath } = require('../../src/core/router/util'); | ||
trusktr marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| describe('router/util', function() { | ||
| it('resolvePath', async function() { | ||
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