ulivz / vuepress-plugin-yuque

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

该项目还维护吗?语雀升级了,运行该脚本不适配了【已解决】 #56

Open cvz6 opened 3 years ago

cvz6 commented 3 years ago

好吧,自问自答 既然没人回应,我自己改。。。 作为一名java coder,没写过nodejs,竟也半google,半看nodejs,给改好了 哈哈哈哈

clone了源码,修改了几个地方:

  1. 报错Language does not exist undefined,各种查询 无果 自己翻源码,发现是node_modules/prismjs/components/index.js 的,是个warn,prismjs是代码美化的插件,应该是我的markdown没指明代码类型 直接写的而不是java 这样,本来想不关了,反正warn,但是打印超级烦,还是想办法给它去了! 源码

    if (!(lang in components.languages)) {
            if (!loadLanguages.silent) {
    //这里给他注释就好了
                // console.warn('Language does not exist: ' + lang);
            }
            return;
        }

    然后发现nodejs没有那种js加载顺序,像java可以在根目录写一个一样包名的类,jvm就会先加载我写的java文件,nodejs没有这种机制,所以我直接改的node_module源码,反正也解决了吧

  2. vuepress 转换md文件各种报错,一堆错误,我就不粘贴了 修复bug,lib/index.js 应该取markdown类型的内容,现在取的html类型的,自然报错! 源码片段如下,直接取data.body || ''就可以了,不用判断 参考语雀的官方文档:https://www.yuque.com/yuque/developer/docdetailserializer image

    postContent = data.body || ''
          // if (useMarkdown || data.format === 'markdown') {
          //   postContent = data.body || ''
          // } else {
          //   postContent = prettify(data.body_html || '')
          // }
        }
  3. 缓存机制不友好,我的知识库500多篇文档,下载一次需要7、8分钟,不能忍受,查看源码发现作者使用conf插件变相实现了缓存,我改成了使用文件系统实现,直接把下载的json存到某目录下,可以查看,方便调试,然后html有问题的话,可以写另一个插件批量修改 去掉他的缓存 image 改为 文档id+最后修改时间为key标识,只下载修改了的文档

    
    index.js中修改

//获取一个知识库的目录结构 https://www.yuque.com/yuque/developer/repo#488246f2 //返回值:https://www.yuque.com/yuque/developer/repo#Response-4

        //返回值没有最后更新时间,需要最后更新时间判断文档是否有更新,有更新时再处理 加快处理时间
        //增加一个接口:获取一个仓库的文档列表 https://www.yuque.com/yuque/developer/doc#6d560c5e
        //返回值:https://www.yuque.com/yuque/developer/docserializer  有创建时间也有更新时间
        let toc = await yuque.getToc()
        let docs = await yuque.getDocs()
        //array转map 加快速度
        let docsMap = new Map();
        for (let doc of docs.data) {
            docsMap.set(doc.slug, doc.updated_at);
        }
        toc.data.forEach(function (t) {
                t.updated_at = docsMap.get(t.slug);
            }
        );

yuque.js中修改下载文档的代码 // todo 更具slug和update_at 取最后更新的文件 //文档不更新则不下载 async getPage(slug, updated_at) { let time = new Date(updatedat).getTime(); let dirFile = `${dir}\json\${slug}${time}.json` //slug+update_at 标识文件唯一性,存在则直接返回硬盘文件,不再下载 //不存在则去语雀下载然后 保存到磁盘 if (fs.existsSync(dirFile)) { let str = fs.readFileSync(dirFile, 'utf8'); return JSON.parse(str); } else { const {status, data} = await Yuque.getPage(this.base, this.repoId, slug); console.log("下载文件:" + slug) let page = { status: status, data: data }; await Yuque.writeFile(dirFile, JSON.stringify(page, null, "\t")); return page; } }

static async writeFile(dirFile, data) {
    //截取目录
    let dir = dirFile.substring(0, dirFile.lastIndexOf('\\'));
    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir);
    }
    fs.writeFileSync(dirFile, data)
}


后来发现vuepress 自动生成md临时文件,也用了起来

4.增加一个新的主题,挺好看的,功能也好 https://vuepress-theme-reco.recoluan.com/

先写这些   ,后续更新自己玩了 

因为我没写过nodejs  就不把代码pr了哈

吐槽:nodejs真的好简单,简陋。。。 写起来很随意,但是不严谨,作为javaer,一两小时就能玩的很熟了,很好玩,语法so easy!!!

完
cvz6 commented 3 years ago

reopen

cvz6 commented 3 years ago

先打开吧,方便后来人查看

AgileQuant commented 3 years ago

感觉跑不了呀$ vuepress dev docs --temp .temp wait Extracting site metadata... tip Apply theme @vuepress/theme-default ... tip Apply plugin container (i.e. "vuepress-plugin-container") ... tip Apply plugin @vuepress/register-components (i.e. "@vuepress/plugin-register-components") ... tip Apply plugin @vuepress/active-header-links (i.e. "@vuepress/plugin-active-header-links") ... tip Apply plugin @vuepress/search (i.e. "@vuepress/plugin-search") ... tip Apply plugin @vuepress/nprogress (i.e. "@vuepress/plugin-nprogress") ... tip Apply plugin vuepress-plugin-yuque ... tip Apply plugin @vuepress/medium-zoom (i.e. "@vuepress/plugin-medium-zoom") ... error @vuepress/internal-site-config apply additionalPages failed. FetchError: request to https://raw.githubusercontent.com/ulivz/vuepress-plugin-yuque/master/CHANGELOG.md failed, reason: getaddrinfo ENOENT raw.githubusercontent.com at ClientRequest. (E:\坚果云同步\6.0 好好学习\1.0 网站开发学习\vue 网站\资源网站\vuepress-plugin-yuque-master\node_modules\node-fetch\lib\index.js:1461:11) at ClientRequest.emit (events.js:315:20) at TLSSocket.socketErrorListener (_http_client.js:426:9) at TLSSocket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:84:21) error Command failed with exit code 1.

cvz6 commented 3 years ago

好吧,因为这个破项目 学会了nodejs和vue。。。。一入node深似海

rootljw commented 3 years ago

感觉跑不了呀$ vuepress dev docs --temp .temp wait Extracting site metadata... tip Apply theme @vuepress/theme-default ... tip Apply plugin container (i.e. "vuepress-plugin-container") ... tip Apply plugin @vuepress/register-components (i.e. "@vuepress/plugin-register-components") ... tip Apply plugin @vuepress/active-header-links (i.e. "@vuepress/plugin-active-header-links") ... tip Apply plugin @vuepress/search (i.e. "@vuepress/plugin-search") ... tip Apply plugin @vuepress/nprogress (i.e. "@vuepress/plugin-nprogress") ... tip Apply plugin vuepress-plugin-yuque ... tip Apply plugin @vuepress/medium-zoom (i.e. "@vuepress/plugin-medium-zoom") ... error @vuepress/internal-site-config apply additionalPages failed. FetchError: request to https://raw.githubusercontent.com/ulivz/vuepress-plugin-yuque/master/CHANGELOG.md failed, reason: getaddrinfo ENOENT raw.githubusercontent.com at ClientRequest. (E:\坚果云同步\6.0 好好学习\1.0 网站开发学习\vue 网站\资源网站\vuepress-plugin-yuque-master\node_modules\node-fetch\lib\index.js:1461:11) at ClientRequest.emit (events.js:315:20) at TLSSocket.socketErrorListener (_http_client.js:426:9) at TLSSocket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:84:21) error Command failed with exit code

遇到相同问题