ulivz / vuepress-plugin-yuque

Input: Yuque Repo, Output: VuePress Site!
https://vuepress-plugin-yuque.ulivz.com
MIT License
304 stars 37 forks source link

multi-repo support #14

Open fleksin opened 5 years ago

fleksin commented 5 years ago

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