Skip to content

Commit

Permalink
fix: show country when province is empty (twikoojs#375)
Browse files Browse the repository at this point in the history
* 改进 访问量统计不再统计来自本地环境(localhost)的访问量 twikoojs#373
* 修复 IP 属地省份不存在时显示国家
* 修复 SHOW_REGION 设置为 false 时仍显示地区 twikoojs#370
* 修复 LIMIT_LENGTH 设置为 0 时 textarea 区域无法输入任何内容 twikoojs#371
  • Loading branch information
imaegoo authored May 12, 2022
1 parent ce56745 commit bed24d1
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn build
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 @@ -13,7 +13,7 @@

<!-- Twikoo -->
<div id="twikoo"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected].9/dist/twikoo.all.min.js" ref="twikooJs"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].10/dist/twikoo.all.min.js" ref="twikooJs"></script>
</div>
</template>
</ParentLayout>
Expand Down
6 changes: 6 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,9 @@ Akismet (Automattic Kismet) 是应用广泛的一个垃圾留言过滤系统,
| 7bu | https://7bu.top | 去不图床,由杜老师提供支持,无免费套餐 |
| smms | https://sm.ms | SMMS 图床,有免费套餐,请自行注册账号,`IMAGE_CDN_TOKEN` 可在 [Dashboard](https://sm.ms/home/apitoken) 中获取 |
| [lsky-pro](https://www.lsky.pro) | 私有部署 | 兰空图床 2.0 版本,`IMAGE_CDN` 请配置图床首页 URL 地址(如 `https://7bu.top`),`IMAGE_CDN_TOKEN` 获取方式请参考教程 [杜老师说图床:新版本去不图床 Token 的获取与清空](https://dusays.com/454/),获取到的 token 格式应为 `1\|1bJbwlqBfnggmOMEZqXT5XusaIwqiZjCDs7r1Ob5`|

## 能私有部署吗?

不能。如果您确实需要支持私有部署评论系统,请优先考虑其他评论系统。

您可以在这个项目 [twikoo-docker](https://github.com/twikoojs/twikoo-docker) 中看到私有部署的实现进度。私有部署存在一系列问题,现阶段作者仍没有时间和精力解决。欢迎贡献。
14 changes: 7 additions & 7 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports.main = require('twikoo-func').main
8. 创建完成后,点击“twikoo"进入云函数详情页,进入“函数代码”标签,点击“文件 - 新建文件”,输入 `package.json`,回车
9. 复制以下代码、粘贴到代码框中,点击“保存并安装依赖”
``` json
{ "dependencies": { "twikoo-func": "1.5.9" } }
{ "dependencies": { "twikoo-func": "1.5.10" } }
```

### 命令行部署
Expand Down Expand Up @@ -175,7 +175,7 @@ twikoo:

``` html
<div id="tcomment"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected].9/dist/twikoo.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].10/dist/twikoo.all.min.js"></script>
<script>
twikoo.init({
envId: '您的环境id', // 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app)
Expand All @@ -189,18 +189,18 @@ twikoo.init({

> 建议使用 CDN 引入 Twikoo 的用户在链接地址上锁定版本,以免将来 Twikoo 升级时受到非兼容性更新的影响。
#### [爆米兔](https://cdn.baomitu.com/) CDN 镜像
#### [Staticfile](https://www.staticfile.org/) CDN 镜像

请参考爆米兔前端静态资源库 [https://cdn.baomitu.com/twikoo](https://cdn.baomitu.com/twikoo)
如果遇到 cdn.jsdelivr.net 加载速度缓慢,可更换七牛云 CDN 镜像。引入的 CDN 链接替换为如下即可:`https://cdn.staticfile.org/twikoo/1.5.10/twikoo.all.min.js`

引入的 CDN 链接替换为如下即可:`https://lib.baomitu.com/twikoo/1.5.9/twikoo.all.min.js`

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

1. 进入[环境-登录授权](https://console.cloud.tencent.com/tcb/env/login),点击“自定义登录”右边的“私钥下载”,下载私钥文件
2. 用文本编辑器打开私钥文件,复制全部内容
3. 点击评论窗口的“小齿轮”图标,粘贴私钥文件内容,并设置管理员密码

配置好登录私钥之后无需留存私钥文件,请勿再次下载登录私钥,否则会导致之前配置的登录私钥失效。

## 版本更新

不同部署方式的更新方式也不同,请对号入座。更新部署成功后,请不要忘记同时更新前端的 Twikoo CDN 地址 `https://cdn.jsdelivr.net/npm/[email protected]/dist/twikoo.all.min.js` 中的 `x.x.x`,使之与云函数版本号相同,然后部署网站。
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": "1.5.9",
"version": "1.5.10",
"description": "A simple comment system based on Tencent CloudBase (tcb).",
"keywords": [
"twikoojs",
Expand Down
11 changes: 7 additions & 4 deletions src/function/twikoo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ function toCommentDto (comment, uid, replies = [], comments = []) {
console.log('bowser 错误:', e)
}
}
const showRegion = !!config.SHOW_REGION && config.SHOW_REGION !== 'false'
return {
id: comment._id,
nick: comment.nick,
Expand All @@ -366,7 +367,7 @@ function toCommentDto (comment, uid, replies = [], comments = []) {
comment: comment.comment,
os: displayOs,
browser: displayBrowser,
ipRegion: config.SHOW_REGION ? getIpRegion({ ip: comment.ip }) : '',
ipRegion: showRegion ? getIpRegion({ ip: comment.ip }) : '',
master: comment.master,
like: comment.like ? comment.like.length : 0,
liked: comment.like ? comment.like.findIndex((item) => item === uid) > -1 : false,
Expand Down Expand Up @@ -1668,11 +1669,13 @@ function getIpRegion ({ ip, detail = false }) {
if (!ip) return ''
try {
const { region } = ipRegionSearcher.btreeSearchSync(ip)
const [,, province, city, isp] = region.split('|')
const [country,, province, city, isp] = region.split('|')
// 有省显示省,没有省显示国家
const area = province.trim() ? province : country
if (detail) {
return province === city ? [city, isp].join(' ') : [province, city, isp].join(' ')
return area === city ? [city, isp].join(' ') : [area, city, isp].join(' ')
} else {
return province
return area
}
} catch (e) {
console.error('IP 属地查询失败:', e)
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": "1.5.9",
"version": "1.5.10",
"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/vercel-min/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "dependencies": { "twikoo-vercel": "1.5.9" } }
{ "dependencies": { "twikoo-vercel": "1.5.10" } }
11 changes: 7 additions & 4 deletions src/vercel/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ function toCommentDto (comment, uid, replies = [], comments = []) {
console.log('bowser 错误:', e)
}
}
const showRegion = !!config.SHOW_REGION && config.SHOW_REGION !== 'false'
return {
id: comment._id.toString(),
nick: comment.nick,
Expand All @@ -398,7 +399,7 @@ function toCommentDto (comment, uid, replies = [], comments = []) {
comment: comment.comment,
os: displayOs,
browser: displayBrowser,
ipRegion: config.SHOW_REGION ? getIpRegion({ ip: comment.ip }) : '',
ipRegion: showRegion ? getIpRegion({ ip: comment.ip }) : '',
master: comment.master,
like: comment.like ? comment.like.length : 0,
liked: comment.like ? comment.like.findIndex((item) => item === uid) > -1 : false,
Expand Down Expand Up @@ -1683,11 +1684,13 @@ function getIpRegion ({ ip, detail = false }) {
if (!ip) return ''
try {
const { region } = ipRegionSearcher.btreeSearchSync(ip)
const [,, province, city, isp] = region.split('|')
const [country,, province, city, isp] = region.split('|')
// 有省显示省,没有省显示国家
const area = province.trim() ? province : country
if (detail) {
return province === city ? [city, isp].join(' ') : [province, city, isp].join(' ')
return area === city ? [city, isp].join(' ') : [area, city, isp].join(' ')
} else {
return province
return area
}
} catch (e) {
console.error('IP 属地查询失败:', e)
Expand Down
2 changes: 1 addition & 1 deletion src/vercel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-vercel",
"version": "1.5.9",
"version": "1.5.10",
"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/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const version = '1.5.9'
const version = '1.5.10'

export { version }
1 change: 1 addition & 0 deletions src/view/components/TkFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
async getCounter () {
const counterEl = document.getElementById('twikoo_visitors')
if (!counterEl) return
if (['localhost', '127.0.0.1', '0.0.0.0'].indexOf(window.location.hostname) !== -1) return
const url = getUrl(this.$twikoo.path)
const result = await call(this.$tcb, 'COUNTER_GET', {
url,
Expand Down
2 changes: 1 addition & 1 deletion src/view/components/TkSubmit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
maxLength () {
let limitLength = parseInt(this.config.LIMIT_LENGTH)
if (Number.isNaN(limitLength)) limitLength = 500
return limitLength
return limitLength > 0 ? limitLength : null
}
},
methods: {
Expand Down

0 comments on commit bed24d1

Please sign in to comment.