Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

multi-repo support #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

multi-repo support #14

wants to merge 5 commits into from

Conversation

fleksin
Copy link

@fleksin fleksin commented Jul 15, 2019

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:

plugins: [
  ...
  [
    'vuepress-plugin-yuque',
   /**
    * new option: multiRepoUrls
    * @property {string} repoRoute - route for the individual repo, must given. doesn't support '/'
    * @property {string} repoUrl - the url of the repo
    */
    multiRepoUrls: [
    {
       repoRoute: 'a',
       repoUrl: 'https://www.yuque.com/zhoufan-jaod3/kb',
     },
     {
       repoRoute: 'b',
       repoUrl: 'https://www.yuque.com/zhoufan-jaod3/cd1bqa',
     },
     ],
  ]
  ....
]

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 at lib/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:
origin

the pic below shows the generated sidebar of the old and the new function side by side
image
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 is lake

I came across some docs where the format is lake, and it would parse data.body_html instead of data.body. In this case the build command will emit compile error and fail , so I have to treat lake format as markdown 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

: typeof source === 'function'
? source(page) === 'markdown'
: false
if (useMarkdown || data.format === 'markdown' || data.format === 'lake') {
Copy link
Author

@fleksin fleksin Jul 15, 2019

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.

Copy link
Owner

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.

Copy link
Owner

@ulivz ulivz left a 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')],
Copy link
Owner

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]],
Copy link
Owner

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)
Copy link
Owner

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',
Copy link
Owner

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')
Copy link
Owner

@ulivz ulivz Jul 21, 2019

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`)
Copy link
Owner

@ulivz ulivz Jul 21, 2019

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`)
Copy link
Owner

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') {
Copy link
Owner

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 {
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants