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

一个小tips,下载制定的知识库 #16

Open
markyun opened this issue Apr 5, 2024 · 3 comments
Open

一个小tips,下载制定的知识库 #16

markyun opened this issue Apr 5, 2024 · 3 comments

Comments

@markyun
Copy link

markyun commented Apr 5, 2024

因为我的知识库文档内容太多,整体下载会卡死或超时。

可以在 getAllBooks 函数中,拿到 bookData 数据后,进行判断,只下载需要的 books 知识库。
code:if (object.books[i].id ===id) {

通过 https://www.yuque.com/api/mine/book_stacks 接口获取 全部 bookData内容,得到book_id。

通过 https://www.yuque.com/api/catalog_nodes?book_id=xxx + id 可以得到当前知识库的全部文章列表 getBookDetail 内容。

@markyun markyun changed the title 一个小tips,只下载制定的知识库 一个小tips,下载制定的知识库 Apr 5, 2024
@Tiang-88
Copy link

可以给一个详细的步骤吗?

@markyun
Copy link
Author

markyun commented Apr 22, 2024

可以给一个详细的步骤吗?

关键code

for (const object of bookData) {
for (let i = 0; i < object.books.length; i++) {
if (booksId && object.books[i].id ===booksId) {
const book = new Book(object.books[i].id, delNonStdChars(object.books[i].name), object.books[i].slug);
console.log("book",book);
book.root = await getBookDetail(page, book);
book.user_url = object.books[i].user.login
books.push(book);
}

    }
}

@fgc346
Copy link

fgc346 commented Jul 10, 2024

根据知识库名称下载特定知识库的步骤

获取知识库的数据结构

  "id": *********,
  "type": "Book",
  "slug": "isowbw",
  "name": "**********",
  "user_id": *********,
  "description": null,
  "items_count": 1,
  "likes_count": 0,
  "watches_count": 0,
  "creator_id": ********,
  "abilities": {
    "read": true,
    "update": true,
    "modify_setting": true,
    "destroy": true,
    "share": true,
    "read_private": true,
    "create_doc": true
  },

重点关注的字段

  • id 知识库的ID
  • name 知识库的名称

关键代码修改

修改文件的路径

src/toc.js

具体代码修改

因为我的知识库全部改成了英文名称,因此,我使用知识库名称过滤。

    for (const object of bookData) {
       // 定义要导出的知识库名称,
        var book_name = "*****";
       // 也可以根据知识库的id过滤,也是由知识库名称找到对应的知识库ID。
        var book_id = "****";
        for (let i = 0; i < object.books.length; i++) {
            // 筛选出 特定的知识库,根据知识库名字进行过滤
            if (book_name == object.books[i].name)
           // if (book_id == object.books[i].id)
            {
              const book = new Book(object.books[i].id, delNonStdChars(object.books[i].name), object.books[i].slug);
              // console.log(`Books information is: `, JSON.stringify(object.books[i]));
  
              // break;
              // continue;
              book.root = await getBookDetail(page, book);
              book.user_url = object.books[i].user.login
              books.push(book);
            }
        }
    }

效果

当执行 node main.js之后,就只下载特定的知识库。

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

3 participants