Skip to content

Commit

Permalink
feat: add hitokoto.api item
Browse files Browse the repository at this point in the history
  • Loading branch information
Renovamen committed Jun 16, 2021
1 parent ebb5455 commit 6a15ea9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
docsDir: "example",
editLinks: true,
lastUpdated: true,
hitokoto: true, // enable hitokoto (一言) or not?
hitokoto: true, // enable hitokoto (一言) or not?
searchIcon: "ri-search-2-line",
languageIcon: "hi-translate",
rss: {
Expand Down
12 changes: 12 additions & 0 deletions example/docs/advanced/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ themeConfig: {

Check [RSS file of this site](/rss.xml) for an example.


## Reading Time

The reading time estimation will be shown on the head of the article by default, supported by [plugin-reading-time](/docs/plugins/reading-time/).
Expand Down Expand Up @@ -122,6 +123,16 @@ A Hitokoto bubble will appear on the home page when `hitokoto` is set to `true`

![hitokoto](/img/docs/hitokoto-bubble.jpg)

Specify `hitokoto.api` to set the query string or use other APIs:

```js
themeConfig: {
hitokoto: {
api: "https://v1.hitokoto.cn/?c=i"
}
}
```


## Math Rendering

Expand Down Expand Up @@ -163,6 +174,7 @@ $$

Create interactive charts in Markdown easily.


### Chart.js

Use JavaScript charting library [Chart.js](https://www.chartjs.org) in Markdown via [plugin-chart](/docs/plugins/chart/):
Expand Down
10 changes: 10 additions & 0 deletions example/zh/docs/advanced/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ themeConfig: {

![hitokoto](/img/docs/hitokoto-bubble.jpg)

如果你想更改一言的请求参数,或想使用其他的接口,可以指定 `hitokoto.api` 项:

```js
themeConfig: {
hitokoto: {
api: "https://v1.hitokoto.cn/?c=i" // 只返回诗词
}
}
```


## 数学公式渲染

Expand Down
16 changes: 9 additions & 7 deletions packages/theme-gungnir/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ export default {
);
window.addEventListener("scroll", throttle(this.handleScroll, 50));
fetch("https://v1.hitokoto.cn")
.then((response) => response.json())
.then((data) => {
const hitokoto = this.$refs.hitokoto;
hitokoto.innerText = data.hitokoto;
})
.catch(console.error);
if (this.$themeConfig.hitokoto) {
fetch(this.$themeConfig.hitokoto.api || "https://v1.hitokoto.cn")
.then((response) => response.json())
.then((data) => {
const hitokoto = this.$refs.hitokoto;
hitokoto.innerText = data.hitokoto;
})
.catch(console.error);
}
},
beforeDestroy() {
Expand Down

0 comments on commit 6a15ea9

Please sign in to comment.