Skip to content
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

能否同步多个语雀空间repo到hexo #29

Open
ichizi opened this issue May 12, 2019 · 14 comments
Open

能否同步多个语雀空间repo到hexo #29

ichizi opened this issue May 12, 2019 · 14 comments

Comments

@ichizi
Copy link

ichizi commented May 12, 2019

No description provided.

@x-cold
Copy link
Owner

x-cold commented May 14, 2019

暂时没有计划。可以具体说说你的需求~

@ichizi
Copy link
Author

ichizi commented May 14, 2019

是这样的,我们团队 在语雀 维护了不同的知识库。
但是现在hexo 只能同步一个知识库的内容,而现在想不同知识库的内容输出到hexo不同的分类下。

@x-cold
Copy link
Owner

x-cold commented Jun 3, 2019

2.0 版本可以支持一下,可能会换一个仓库名字,以更好的支持扩展

@xxb
Copy link

xxb commented Apr 11, 2020

这竟然是个小众需求吗?

@wztlink1013

This comment has been minimized.

@CCKNBC

This comment has been minimized.

@yizhichangyuan
Copy link

需求+3

@qdwds
Copy link

qdwds commented Sep 29, 2021

需求+4

@xinc-it
Copy link

xinc-it commented Oct 16, 2021

需求+5

@lonbaw
Copy link

lonbaw commented Nov 6, 2021

需求+6

@wxharry
Copy link

wxharry commented May 20, 2022

请问还会更新这个功能吗?我非常愿意为2.0版本贡献代码

@earthaYan
Copy link

需求+10086

@bazijun
Copy link

bazijun commented Oct 12, 2022

需求 + 10087

@bazijun
Copy link

bazijun commented Oct 17, 2022

我写了个简陋的脚本,可以解决这个问题,将该脚本加入你的构建过程中即可。
@x-cold

syncAllYuqueRepo.js

多仓库肯定意味着多个缓存文件,所有缓存可以装在一个文件夹中。但需要先创建yuqueCache文件夹不然会报错。

const FS = require('fs');
const spawn = require('cross-spawn');
const packageJson = require('./package.json')
// 扩展该列表即可实现多仓库同步
const yuqueConfigList = [
    {
        name: "仓库A",
        postPath: "source/_posts/repoA",
        cachePath: "yuqueCache/repoA.json",
        repo: "仓库A的repo",
    },
    {
        name: "仓库B",
        postPath: "source/_posts/repoB",
        cachePath: "yuqueCache/repoB.json",
        repo: "仓库B的repo",
    },
]

// 按照 yuqueConfigList 替换 yuqueConfig中的地址,仓库名,缓存地址。并逐个触发语雀文档同步。
for (const repo of yuqueConfigList) {
    packageJson.yuqueConfig.postPath = repo.postPath
    packageJson.yuqueConfig.cachePath = repo.cachePath
    packageJson.yuqueConfig.repo = repo.repo
    FS.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2));
    console.log('\n[sync]===>', repo.name, '<===[sync]');
    spawn.sync('yarn', ['sync'], { stdio: 'inherit' })
}

package.json

"scripts": {
    "sync": "yuque-hexo sync",
    "clean:yuque": "rimraf yuqueCache/*",
    "clean:yuque:linux": "rm -rf yuqueCache/*",
    "build": "node syncAllYuqueRepo.js && hexo clean && hexo g -d",
    "server": "node syncAllYuqueRepo.js && hexo clean && hexo g && hexo s",
  },
  ...
  "yuqueConfig": {
    "postPath": "source/_posts/xxx",
    "cachePath": "yuqueCache/yuque_xxx.json",
    "mdNameFormat": "title",
    "adapter": "hexo",
    "concurrency": 5,
    "baseUrl": "https://www.yuque.com/api/v2",
    "login": "你的login",
    "repo": "你的repo",
    "token": "你的token"
  }

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

No branches or pull requests