Last active
August 16, 2019 01:36
-
-
Save banyudu/5fd6f8ea7782ea0bbd5117345f6b16c5 to your computer and use it in GitHub Desktop.
Fetch table of contents from Yuque by token and bookId
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as SDK from '@yuque/sdk' | |
import * as YAML from 'yaml' | |
const getToc = async (token: string, bookId: number | string) => { | |
const client = new SDK({ | |
token: token || process.env.YUQUE_TOKEN || undefined | |
}) | |
const repo = await client.repos.get({ | |
namespace: bookId // bookId | |
}) | |
const tocStr = repo.toc_yml | |
const toc = YAML.parse(tocStr) | |
return toc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment