Skip to content

Instantly share code, notes, and snippets.

@banyudu
Last active August 16, 2019 01:36
Show Gist options
  • Save banyudu/5fd6f8ea7782ea0bbd5117345f6b16c5 to your computer and use it in GitHub Desktop.
Save banyudu/5fd6f8ea7782ea0bbd5117345f6b16c5 to your computer and use it in GitHub Desktop.
Fetch table of contents from Yuque by token and bookId
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