From 8a77af4081d7181058e1d2b516a43a5a00fb79d5 Mon Sep 17 00:00:00 2001 From: ppoffice Date: Sat, 20 Aug 2022 12:10:55 -0400 Subject: [PATCH] fix(*): add more twikoo options --- src/schema/comment/twikoo.json | 13 ++++++++++++- src/view/comment/twikoo.jsx | 22 +++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/schema/comment/twikoo.json b/src/schema/comment/twikoo.json index 71d55127..b0e7d3a3 100644 --- a/src/schema/comment/twikoo.json +++ b/src/schema/comment/twikoo.json @@ -10,7 +10,18 @@ }, "env_id": { "type": "string", - "description": "envId from Tencent CloudBase" + "description": "envId from Tencent CloudBase or Vercel URL" + }, + "region": { + "type": "string", + "description": "Region of Tencent CloudBase", + "nullable": true + }, + "lang": { + "type": "string", + "description": "i18n support", + "default": "zh-CN", + "nullable": true } }, "required": ["type", "env_id"] diff --git a/src/view/comment/twikoo.jsx b/src/view/comment/twikoo.jsx index 5dc157a3..29bc8bdf 100644 --- a/src/view/comment/twikoo.jsx +++ b/src/view/comment/twikoo.jsx @@ -11,14 +11,18 @@ const { cacheComponent } = require('../../util/cache'); * @see https://twikoo.js.org/quick-start.html * @example * */ class Twikoo extends Component { render() { - const { env_id, jsUrl } = this.props; + const { envId, region, lang, jsUrl } = this.props; const js = `Twikoo.init({ - env_id: '${env_id}' + env_id: '${envId}', + ${region ? `region: ${JSON.stringify(region)},` : ''} + ${lang ? `lang: ${JSON.stringify(lang)},` : ''} });`; return ( @@ -40,15 +44,19 @@ class Twikoo extends Component { * @example * */ Twikoo.Cacheable = cacheComponent(Twikoo, 'comment.twikoo', (props) => { - const { comment } = props; + const { comment, helper, page, config } = props; return { - env_id: comment.env_id, - jsUrl: 'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/twikoo/1.4.18/twikoo.all.min.js', + envId: comment.env_id, + region: comment.region, + lang: comment.lang || page.lang || page.language || config.language || 'zh-CN', + jsUrl: helper.cdn('twikoo', '1.4.18', 'dist/twikoo.all.min.js'), }; });