-
-
Notifications
You must be signed in to change notification settings - Fork 37
multi-repo support #14
base: master
Are you sure you want to change the base?
Conversation
: typeof source === 'function' | ||
? source(page) === 'markdown' | ||
: false | ||
if (useMarkdown || data.format === 'markdown' || data.format === 'lake') { |
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 need some opinion on whether this change would break anything.
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.
If you parse the "lake" as markdown by default, you'll lose some of the styles which is only available in body_html
, e.g. width of images.
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, please address the comments and write unit tests for the new getSidebar
function.
lib/index.js
Outdated
enhanceAppFiles: [ | ||
path.join(__dirname, 'client.js') | ||
], | ||
enhanceAppFiles: [path.join(__dirname, 'client.js')], |
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 not format unrelated codes.
lib/index.js
Outdated
plugins: [ | ||
['@vuepress/medium-zoom', true], | ||
], | ||
plugins: [['@vuepress/medium-zoom', true]], |
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.
Same here.
lib/index.js
Outdated
config | ||
.options | ||
.html(false) | ||
config.options.html(false) |
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.
Same here.
lib/index.js
Outdated
|
||
if (repoId) { | ||
assert( | ||
typeof repoId === 'string' || | ||
typeof repoId === 'number', | ||
typeof repoId === 'string' || typeof repoId === 'number', |
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.
Same here.
`[${PACKAGE_NAME}] repoId should be string or number, but got ${repoId}` | ||
) | ||
} else if (repoUrl) { | ||
assert( | ||
typeof repoUrl === 'string', | ||
`[${PACKAGE_NAME}] repoUrl should be string, but got ${repoId}` | ||
) | ||
} else if (multiRepoUrls) { | ||
assert(Array.isArray(multiRepoUrls), 'multiRepoUrls must be array') |
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.
multiRepoUrls must be array
=> expect "multiRepoUrls" to be an array
} else if (multiRepoUrls) { | ||
assert(Array.isArray(multiRepoUrls), 'multiRepoUrls must be array') | ||
multiRepoUrls.forEach(repo => { | ||
assert(typeof repo === 'object', `[${PACKAGE_NAME}] multiRepoUrls must be object`) |
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.
expect each item of "multiRepoUrls" to be a plain object
assert(Array.isArray(multiRepoUrls), 'multiRepoUrls must be array') | ||
multiRepoUrls.forEach(repo => { | ||
assert(typeof repo === 'object', `[${PACKAGE_NAME}] multiRepoUrls must be object`) | ||
assert('repoRoute' in repo, `[${PACKAGE_NAME}] must have repoRoute for multiRepoUrls`) |
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.
expect each item of "multiRepoUrls" to have a field "repoRoute"
: typeof source === 'function' | ||
? source(page) === 'markdown' | ||
: false | ||
if (useMarkdown || data.format === 'markdown' || data.format === 'lake') { |
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.
If you parse the "lake" as markdown by default, you'll lose some of the styles which is only available in body_html
, e.g. width of images.
|
||
const { |
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 not format unrelated codes.
Usage
As title suggested, this PR is aimed to add new capability to extract and display multiple doc repos at the same time.
To Achieve that, I added new options for multiple repos supports:
multiRepoUrls
example:
So for each repo, you have to assign a unique
repoRoute
, which will be added into router.Design
So one of the obstacles is to resolve multiple sidebar.
Luckily vuepress supports multiple sidebar:
https://v1.vuepress.vuejs.org/theme/default-theme-config.html#multiple-sidebars
which is why the new option requires
repoRoute
as an input.After that there is not much trouble implementing multiple repos.
Changes
There are couple of things that I changed during the course.
rewrote
getSideBarByToc
function atlib/getSideBar.js
I basically rewrote this function because the old one has bug and it's hard to fix the bug within the old code.

The old function has a problem recognizing a node's position in the tree. If the depth of previous node is greater than current node by more than 1, its position will be messed up.
take this doc's sidebar for example: https://www.yuque.com/zhoufan-jaod3/cd1bqa/zwcaqw
the original sidebar from yuque should be like this:
the pic below shows the generated sidebar of the old and the new function side by side

the left one is using the old function which is incorrect
the right one is the result of the new function
I'm considering adding more unit tests for the new function.
parse the body as
markdown
when format islake
I came across some docs where the format is
lake
, and it would parsedata.body_html
instead ofdata.body
. In this case the build command will emit compile error and fail , so I have to treatlake
format asmarkdown
to get around it. I don't know the initial motive of this design, so I think I need some opinion on whether this change would break anything.portal to that line: https://github.com/ulivz/vuepress-plugin-yuque/pull/14/files#r303388389