Skip to content

Commit

Permalink
fix(*): add more twikoo options
Browse files Browse the repository at this point in the history
  • Loading branch information
ppoffice committed Aug 20, 2022
1 parent 3ef4328 commit 8a77af4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
13 changes: 12 additions & 1 deletion src/schema/comment/twikoo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
22 changes: 15 additions & 7 deletions src/view/comment/twikoo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ const { cacheComponent } = require('../../util/cache');
* @see https://twikoo.js.org/quick-start.html
* @example
* <Twikoo
* env_id="Vercel Domain"
* envId="env_id"
* region="ap-guangzhou"
* lang="zh-CN"
* jsUrl="/path/to/Twikoo.js" />
*/
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 (
<Fragment>
Expand All @@ -40,15 +44,19 @@ class Twikoo extends Component {
* @example
* <Twikoo.Cacheable
* comment={{
* env_id: "https://path/to/vercel/domain"
* env_id: "env_id",
* region: "ap-guangzhou",
* lang: "zh-CN",
* }} />
*/
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'),
};
});

Expand Down

1 comment on commit 8a77af4

@ppoffice
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#51

Please sign in to comment.