Skip to content

Commit

Permalink
feat: add urls parameter to getRecentComments (twikoojs#626)
Browse files Browse the repository at this point in the history
* feat: add urls parameter to getRecentComments (twikoojs#626)
* feat: add urls parameter to getRecentComments
* doc: add huggingface guide, modify vercel guide
* doc: update tcb node version
  • Loading branch information
imaegoo authored Dec 11, 2023
1 parent 61740ea commit af817d9
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/Twikoo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ onMounted(() => {

<!-- Twikoo -->
<div id="twikoo"></div>
<component :is="'script'" src="https://cdn.jsdelivr.net/npm/[email protected].26/dist/twikoo.all.min.js" ref="twikooJs"></component>
<component :is="'script'" src="https://cdn.jsdelivr.net/npm/[email protected].27/dist/twikoo.all.min.js" ref="twikooJs"></component>
</div>
</template>
5 changes: 5 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ twikoo.getCommentsCount({
twikoo.getRecentComments({
envId: '您的环境id', // 环境 ID
// region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai,如果您的环境地域不是上海,需传此参数
urls: [ // 要求云函数版本 >= 1.6.27。不包含协议、域名、参数的文章路径列表,不传默认获取所有最新评论
'/2020/10/post-1.html',
'/2020/11/post-2.html',
'/2020/12/post-3.html'
],
pageSize: 10, // 获取多少条,默认:10,最大:100
includeReply: false // 是否包括最新回复,默认:false
}).then(function (res) {
Expand Down
25 changes: 19 additions & 6 deletions docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| [Railway 部署](#railway-部署) | ★★☆☆☆ | 有免费额度但不足以支持一个月连续运行,部署简单,适合全球访问。 |
| [Zeabur 部署](#zeabur-部署) | ★☆☆☆☆ | 需要绑定支付宝或信用卡,部署简单,适合中国大陆访问,免费计划环境随时可能会被删除。 |
| [Netlify 部署](#netlify-部署) | ★★★★☆ | 有充足的免费额度,中国大陆访问速度不错。 |
| [Hugging Face 部署](#hugging-face-部署) | ★☆☆☆☆ | 免费,不稳定,正在测试中 |
| [私有部署](#私有部署) | ★★☆☆☆ | 适用于有服务器的用户,需要自行申请 HTTPS 证书。 |
| [私有部署 (Docker)](#私有部署-docker) | ★★★☆☆ | 适用于有服务器的用户,需要自行申请 HTTPS 证书。 |

Expand All @@ -34,15 +35,15 @@
3. 进入[环境-登录授权](https://console.cloud.tencent.com/tcb/env/login),启用“匿名登录”
4. 进入[环境-安全配置](https://console.cloud.tencent.com/tcb/env/safety),将网站域名添加到“WEB安全域名”
5. 进入[环境-云函数](https://console.cloud.tencent.com/tcb/scf/index),点击“新建云函数”
6. 函数名称请填写:`twikoo`,创建方式请选择:`空白函数`,运行环境请选择:`Nodejs 10.15`,函数内存请选择:`128MB`,点击“下一步”
6. 函数名称请填写:`twikoo`,创建方式请选择:`空白函数`,运行环境请选择:`Nodejs 16.13`,函数内存请选择:`128MB`,点击“下一步”
7. 清空输入框中的示例代码,复制以下代码、粘贴到“函数代码”输入框中,点击“确定”
``` js
exports.main = require('twikoo-func').main
```
8. 创建完成后,点击“twikoo"进入云函数详情页,进入“函数代码”标签,点击“文件 - 新建文件”,输入 `package.json`,回车
9. 复制以下代码、粘贴到代码框中,点击“保存并安装依赖”
``` json
{ "dependencies": { "twikoo-func": "1.6.26" } }
{ "dependencies": { "twikoo-func": "1.6.27" } }
```

## 腾讯云命令行部署
Expand Down Expand Up @@ -108,12 +109,16 @@ Vercel 部署的环境需配合 1.4.0 以上版本的 twikoo.js 使用
6. 申请 [Vercel](https://vercel.com/signup) 账号
7. 点击以下按钮将 Twikoo 一键部署到 Vercel<br>

[![](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/twikoojs/twikoo/tree/main/src/server/vercel-min)
[![Deploy](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/twikoojs/twikoo/tree/main/src/server/vercel-min)

8. 进入 Settings - Environment Variables,添加环境变量 `MONGODB_URI`,值为前面记录的数据库连接字符串
9. 进入 Deployments , 然后在任意一项后面点击更多(三个点) , 然后点击Redeploy , 最后点击下面的Redeploy
10. 进入 Overview,点击 Domains 下方的链接,如果环境配置正确,可以看到 “Twikoo 云函数运行正常” 的提示
11. Vercel Domains(包含 `https://` 前缀,例如 `https://xxx.vercel.app`)即为您的环境 id
9. 进入 Settings - Deployment Protection,设置 Vercel Authentication 为 Disabled,并 Save

![](./static/vercel-1.png)

10. 进入 Deployments , 然后在任意一项后面点击更多(三个点) , 然后点击 Redeploy , 最后点击下面的 Redeploy
11. 进入 Overview,点击 Domains 下方的链接,如果环境配置正确,可以看到 “Twikoo 云函数运行正常” 的提示
12. Vercel Domains(包含 `https://` 前缀,例如 `https://xxx.vercel.app`)即为您的环境 id

## Railway 部署

Expand Down Expand Up @@ -192,6 +197,14 @@ Netlify 免费等级(Functions Level 0)支持每月 125,000 请求次数和

13. 云函数地址(包含 `https://` 前缀和 `/.netlify/functions/twikoo` 后缀,例如 `https://xxx.netlify.app/.netlify/functions/twikoo`)即为您的环境 id

## Hugging Face 部署

::: warning 注意
正在测试中,文档待完善
:::

请参考 [https://github.com/twikoojs/twikoo/blob/main/src/server/huggingface-space/README.md](https://github.com/twikoojs/twikoo/blob/main/src/server/huggingface-space/README.md),更详细的文档会在未来版本中完善。

## 私有部署

::: warning 注意
Expand Down
10 changes: 5 additions & 5 deletions docs/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ twikoo:

``` html
<div id="tcomment"></div>
<script src="https://cdn.staticfile.org/twikoo/1.6.26/twikoo.all.min.js"></script>
<script src="https://cdn.staticfile.org/twikoo/1.6.27/twikoo.all.min.js"></script>
<script>
twikoo.init({
envId: '您的环境id', // 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app)
Expand All @@ -103,10 +103,10 @@ twikoo.init({

如果遇到默认 CDN 加载速度缓慢,可更换其他 CDN 镜像。以下为可供选择的公共 CDN,其中一些 CDN 可能需要数天时间同步最新版本:

* `https://cdn.staticfile.org/twikoo/1.6.26/twikoo.all.min.js`
* `https://lib.baomitu.com/twikoo/1.6.26/twikoo.all.min.js`
* `https://cdn.bootcdn.net/ajax/libs/twikoo/1.6.26/twikoo.all.min.js`
* `https://cdn.jsdelivr.net/npm/[email protected].26/dist/twikoo.all.min.js`
* `https://cdn.staticfile.org/twikoo/1.6.27/twikoo.all.min.js`
* `https://lib.baomitu.com/twikoo/1.6.27/twikoo.all.min.js`
* `https://cdn.bootcdn.net/ajax/libs/twikoo/1.6.27/twikoo.all.min.js`
* `https://cdn.jsdelivr.net/npm/[email protected].27/dist/twikoo.all.min.js`

## 开启管理面板(腾讯云环境)

Expand Down
Binary file added docs/static/hugging-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/hugging-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/vercel-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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": "1.6.26",
"version": "1.6.27",
"description": "A simple comment system.",
"keywords": [
"twikoojs",
Expand Down
2 changes: 1 addition & 1 deletion src/client/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const version = '1.6.26'
const version = '1.6.27'

export { version }
3 changes: 3 additions & 0 deletions src/server/function/twikoo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ async function getRecentComments (event) {
try {
const query = {}
query.isSpam = _.neq(true)
if (event.urls && event.urls.length) {
query.url = _.in(getUrlsQuery(event.urls))
}
if (!event.includeReply) query.rid = _.in(['', null])
if (event.pageSize > 100) event.pageSize = 100
const result = await db
Expand Down
2 changes: 1 addition & 1 deletion src/server/function/twikoo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-func",
"version": "1.6.26",
"version": "1.6.27",
"description": "A simple comment system.",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/server/netlify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-netlify",
"version": "1.6.26",
"version": "1.6.27",
"description": "A simple comment system.",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions src/server/self-hosted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ async function getRecentComments (event) {
try {
const query = {}
query.isSpam = { $ne: true }
if (event.urls && event.urls.length) {
query.url = { $in: getUrlsQuery(event.urls) }
}
if (!event.includeReply) query.rid = { $exists: false }
if (event.pageSize > 100) event.pageSize = 100
const result = db
Expand Down
3 changes: 3 additions & 0 deletions src/server/self-hosted/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@ async function getRecentComments (event) {
try {
const query = {}
query.isSpam = { $ne: true }
if (event.urls && event.urls.length) {
query.url = { $in: getUrlsQuery(event.urls) }
}
if (!event.includeReply) query.rid = { $in: ['', null] }
if (event.pageSize > 100) event.pageSize = 100
const result = await db
Expand Down
4 changes: 2 additions & 2 deletions src/server/self-hosted/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tkserver",
"version": "1.6.26",
"version": "1.6.27",
"description": "A simple comment system.",
"keywords": [
"twikoo",
Expand Down Expand Up @@ -31,7 +31,7 @@
"get-user-ip": "^1.0.1",
"lokijs": "^1.5.12",
"mongodb": "^3.6.3",
"twikoo-func": "1.6.26",
"twikoo-func": "1.6.27",
"uuid": "^8.3.2"
}
}
5 changes: 4 additions & 1 deletion src/server/vercel/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ async function commentSubmit (event, request) {
])
logger.log('POST_SUBMIT')
} catch (e) {
logger.error('POST_SUBMIT 失败', e)
logger.error('POST_SUBMIT 失败', e.message)
}
return res
}
Expand Down Expand Up @@ -827,6 +827,9 @@ async function getRecentComments (event) {
try {
const query = {}
query.isSpam = { $ne: true }
if (event.urls && event.urls.length) {
query.url = { $in: getUrlsQuery(event.urls) }
}
if (!event.includeReply) query.rid = { $in: ['', null] }
if (event.pageSize > 100) event.pageSize = 100
const result = await db
Expand Down
4 changes: 2 additions & 2 deletions src/server/vercel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-vercel",
"version": "1.6.26",
"version": "1.6.27",
"description": "A simple comment system.",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand All @@ -13,7 +13,7 @@
"dependencies": {
"get-user-ip": "^1.0.1",
"mongodb": "^3.6.3",
"twikoo-func": "1.6.26",
"twikoo-func": "1.6.27",
"uuid": "^8.3.2"
}
}

0 comments on commit af817d9

Please sign in to comment.