diff --git a/example/.vuepress/config.js b/example/.vuepress/config.js index a2c9c724..37907eba 100644 --- a/example/.vuepress/config.js +++ b/example/.vuepress/config.js @@ -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: { diff --git a/example/docs/advanced/features.md b/example/docs/advanced/features.md index 3f0fc5f5..f4169cea 100644 --- a/example/docs/advanced/features.md +++ b/example/docs/advanced/features.md @@ -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/). @@ -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 @@ -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/): diff --git a/example/zh/docs/advanced/features.md b/example/zh/docs/advanced/features.md index 52111a9b..b0217d87 100644 --- a/example/zh/docs/advanced/features.md +++ b/example/zh/docs/advanced/features.md @@ -116,6 +116,16 @@ themeConfig: { ![hitokoto](/img/docs/hitokoto-bubble.jpg) +如果你想更改一言的请求参数,或想使用其他的接口,可以指定 `hitokoto.api` 项: + +```js +themeConfig: { + hitokoto: { + api: "https://v1.hitokoto.cn/?c=i" // 只返回诗词 + } +} +``` + ## 数学公式渲染 diff --git a/packages/theme-gungnir/components/Home.vue b/packages/theme-gungnir/components/Home.vue index e997ee93..c701b0cc 100644 --- a/packages/theme-gungnir/components/Home.vue +++ b/packages/theme-gungnir/components/Home.vue @@ -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() {