Skip to content

Commit

Permalink
docs: 添加 twoslash (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikaibenkai authored Mar 17, 2024
1 parent 7b53bd9 commit 8c40341
Show file tree
Hide file tree
Showing 7 changed files with 661 additions and 6 deletions.
13 changes: 13 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from 'vitepress'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'

export default defineConfig({
title: 'Fanbook API Node.js SDK',
Expand All @@ -7,6 +8,18 @@ export default defineConfig({
['link', { rel: 'icon', href: '/icon/fanbook.svg' }],
],
lang: 'zh-CN',
markdown: {
codeTransformers: [
transformerTwoslash({
explicitTrigger: false,
twoslashOptions: {
handbookOptions: {
noErrors: true,
},
},
}),
],
},
themeConfig: {
nav: [
{ text: '首页', link: '/' },
Expand Down
11 changes: 11 additions & 0 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Theme from 'vitepress/theme'
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import '@shikijs/vitepress-twoslash/style.css'
import type { EnhanceAppContext } from 'vitepress'

export default {
extends: Theme,
enhanceApp({ app }: EnhanceAppContext) {
app.use(TwoslashFloatingVue)
},
}
5 changes: 4 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"type": "module"
"type": "module",
"devDependencies": {
"fanbook-api-node-sdk": "link:.."
}
}
10 changes: 10 additions & 0 deletions docs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions docs/reference/api-calling.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ console.log(await bot.sendMessage(CHAT_ID, CONTENT, CONTENT))
```ts
import { Bot } from 'fanbook-api-node-sdk'

const BOT_TOKEN = '在此填入你的机器人令牌'
const bot = new Bot(BOT_TOKEN, {
// ---cut---
const bot = new Bot('在此填入你的机器人令牌', {
axios: { // axios 选项
timeout: 3 * 1000,
timeoutErrorMessage: 'Timeout 3000ms',
Expand All @@ -131,12 +131,12 @@ const bot = new Bot(BOT_TOKEN, {

对于 SDK 还未支持的 API,你可以直接使用 axios 实例:

```ts
```ts{7}
import { Bot } from 'fanbook-api-node-sdk'
const BOT_TOKEN = '在此填入你的机器人令牌'
const bot = new Bot(BOT_TOKEN)
const bot = new Bot('在此填入你的机器人令牌')
// ---cut---
// baseURL 是 `https://a1.fanbook.mobi/api/bot/${this.token}`
await bot.axios.post('/path/to/api')
```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"devDependencies": {
"@antfu/eslint-config": "^2.6.3",
"@inquirer/prompts": "^4.0.0",
"@shikijs/vitepress-twoslash": "^1.2.0",
"@swc/core": "^1.3.100",
"@swc/helpers": "^0.5.3",
"@swc/jest": "^0.2.29",
Expand Down
Loading

0 comments on commit 8c40341

Please sign in to comment.