Skip to content

Commit

Permalink
fix(doc): 完善文档 优化评论速度 发布正式版 (#100)
Browse files Browse the repository at this point in the history
* 改进 异步发送评论通知,加快评论响应速度
* 文档 完善文档
  • Loading branch information
imaegoo authored Jan 11, 2021
1 parent 702b3f3 commit 484c057
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 iMaeGoo
Copyright (c) 2020-present iMaeGoo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion docs/.vuepress/theme/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
<div id="twikoo"></div>
<script src="https://cdn.jsdelivr.net/npm/twikoo@0.6.0/dist/twikoo.all.min.js" ref="twikooJs"></script>
<script src="https://cdn.jsdelivr.net/npm/twikoo@1.0.0/dist/twikoo.all.min.js" ref="twikooJs"></script>
</div>
</template>
</ParentLayout>
Expand Down
32 changes: 27 additions & 5 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Twikoo 分为云函数和前端两部分,部署时请注意保存二者版本

### 手动部署

如果您打算部署到一个现有的云开发环境,请直接从第 5 步开始。
如果您打算部署到一个现有的云开发环境,请直接从第 3 步开始。

1. [注册云开发CloudBase](https://curl.qcloud.com/KnnJtUom)
2. 进入[云开发控制台](https://console.cloud.tencent.com/tcb/),新建环境,请按需配置环境<br>
Expand All @@ -45,7 +45,7 @@ exports.main = require('twikoo-func').main
8. 创建完成后,点击“twikoo"进入云函数详情页,进入“函数代码”标签,点击“文件 - 新建文件”,输入 `package.json`,回车
9. 复制以下代码、粘贴到代码框中,点击“保存并安装依赖”
``` json
{ "dependencies": { "twikoo-func": "0.6.0" } }
{ "dependencies": { "twikoo-func": "1.0.0" } }
```

### 命令行部署
Expand All @@ -58,7 +58,7 @@ exports.main = require('twikoo-func').main
* 请勿在 Termux 下操作。虽然可以部署成功,但是使用时会报错 `[FUNCTIONS_EXECUTE_FAIL] Error: EACCES: permission denied, open '/var/user/index.js'`
:::

如果您打算部署到一个现有的云开发环境,请直接从第 5 步开始。
如果您打算部署到一个现有的云开发环境,请直接从第 3 步开始。

1. [注册云开发CloudBase](https://curl.qcloud.com/KnnJtUom)
2. 进入[云开发控制台](https://console.cloud.tencent.com/tcb/),新建环境,请按需配置环境<br>
Expand Down Expand Up @@ -98,7 +98,7 @@ Volantis 目前支持 Twikoo,请查看 [hexo-theme-volantis/_config.yml](https
``` yml
comments:
twikoo:
js: https://cdn.jsdelivr.net/npm/twikoo@0.6.0/dist/twikoo.all.min.js
js: https://cdn.jsdelivr.net/npm/twikoo@1.0.0/dist/twikoo.all.min.js
envId: xxxxxxxxxxxxxxx # 腾讯云环境id
```
Expand All @@ -111,6 +111,28 @@ twikoo:
envId: xxxxxxxxxxxxxxx # 腾讯云环境id
```
### 在 Hexo NexT 主题使用
在 Hexo 项目根目录执行 `npm install hexo-next-twikoo`,然后在配置中添加

``` yml
twikoo:
enable: true
visitor: true
envId: xxxxxxxxxxxxxxx # 腾讯云环境id
# region: ap-guangzhou # 环境地域,默认为 ap-shanghai
```

### 在 Hexo Matery 主题使用

``` yml
twikoo:
enable: true
envId: xxxxxxxxxxxxxxx # 环境 ID,搭建教程:https://twikoo.js.org/quick-start.html
# region: ap-guangzhou # 环境地域,默认为 ap-shanghai
# path: 'window.location.pathname' # 自定义文章路径
```

### 在 Hexo Icarus 主题使用

请参考 [基于腾讯云,给你的 Icarus 博客配上 Twikoo 评论系统](https://anzifan.com/post/icarus_to_candy_2/) by 异次元de机智君💯
Expand All @@ -123,7 +145,7 @@ twikoo:

``` html
<div id="tcomment"></div>
<script src="https://cdn.jsdelivr.net/npm/twikoo@0.6.0/dist/twikoo.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/twikoo@1.0.0/dist/twikoo.all.min.js"></script>
<script>
twikoo.init({
envId: '您的环境id',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo",
"version": "0.6.0",
"version": "1.0.0",
"description": "A simple comment system based on Tencent CloudBase (tcb).",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
21 changes: 21 additions & 0 deletions src/function/twikoo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020-present iMaeGoo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions src/function/twikoo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Twikoo 云函数

[![](https://img.shields.io/npm/v/twikoo-func)](https://www.npmjs.com/package/twikoo-func)
[![](https://img.shields.io/npm/l/twikoo-func)](./LICENSE)

使用说明:https://twikoo.js.org
20 changes: 16 additions & 4 deletions src/function/twikoo/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Twikoo cloudbase function v0.6.0
* Twikoo cloudbase function v1.0.0
* (c) 2020-2021 iMaeGoo
* Released under the MIT License.
*/
Expand Down Expand Up @@ -31,7 +31,7 @@ const window = new JSDOM('').window
const DOMPurify = createDOMPurify(window)

// 常量 / constants
const VERSION = '0.6.0'
const VERSION = '1.0.0'
const RES_CODE = {
SUCCESS: 0,
FAIL: 1000,
Expand Down Expand Up @@ -116,6 +116,9 @@ exports.main = async (event, context) => {
case 'CHECK_SPAM':
res = await checkSpamAction(event, context)
break
case 'SEND_MAIL':
res = await sendMail(event.comment, context)
break
default:
if (event.event) {
res.code = RES_CODE.EVENT_NOT_EXIST
Expand Down Expand Up @@ -715,7 +718,14 @@ async function commentSubmit (event) {
}
const comment = await save(event)
res.id = comment.id
await sendMail(comment)
try {
await app.callFunction({
name: 'twikoo',
data: { event: 'SEND_MAIL', comment }
}, { timeout: 300 }) // 设置较短的 timeout 来实现异步
} catch (e) {
console.log('开始异步发送评论通知')
}
return res
}

Expand All @@ -730,13 +740,15 @@ async function save (event) {
}

// 发送通知
async function sendMail (comment) {
async function sendMail (comment, context) {
if (!isRecursion(context)) return { code: RES_CODE.FORBIDDEN }
await Promise.all([
noticeMaster(comment),
noticeReply(comment),
noticeWeChat(comment),
noticeQQ(comment)
]).catch(console.error)
return { code: RES_CODE.SUCCESS }
}

// 初始化邮件插件
Expand Down
2 changes: 1 addition & 1 deletion src/function/twikoo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-func",
"version": "0.6.0",
"version": "1.0.0",
"description": "A simple comment system based on Tencent CloudBase (tcb).",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/view/components/TkAdminConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
{ key: 'MASTER_TAG', desc: t('ADMIN_CONFIG_ITEM_MASTER_TAG'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}站长`, value: '' },
{ key: 'COMMENT_BG_IMG', desc: t('ADMIN_CONFIG_ITEM_COMMENT_BG_IMG'), ph: '', value: '' },
{ key: 'GRAVATAR_CDN', desc: t('ADMIN_CONFIG_ITEM_GRAVATAR_CDN'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}sdn.geekzu.org`, value: '' },
{ key: 'DEFAULT_GRAVATAR', desc: t('ADMIN_CONFIG_ITEM_DEFAULT_GRAVATAR'), ph: '', value: '' },
{ key: 'DEFAULT_GRAVATAR', desc: t('ADMIN_CONFIG_ITEM_DEFAULT_GRAVATAR'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}mp`, value: '' },
{ key: 'COMMENT_PLACEHOLDER', desc: t('ADMIN_CONFIG_ITEM_COMMENT_PLACEHOLDER'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}`, value: '' },
{ key: 'REQUIRED_FIELDS', desc: t('ADMIN_CONFIG_ITEM_REQUIRED_FIELDS'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}nick,mail,link`, value: '' },
{ key: 'HIDE_ADMIN_CRYPT', desc: t('ADMIN_CONFIG_ITEM_HIDE_ADMIN_CRYPT'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}admin`, value: '' }
Expand Down

0 comments on commit 484c057

Please sign in to comment.