diff --git a/README.md b/README.md index bbf6c1b..a957da7 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ 完整主题列表参见 [common/theme.js](./common/theme.js) ,或参见 [github-readme-stats 中的主题列表](https://github.com/anuraghazra/github-readme-stats/tree/master/themes)。 +### 支持的语言列表 + +默认语言为英文,如果想要更改为中文显示,在 url 后加入 `&lang=zh-CN` 即可,例如: +
+ + +
+ ## 演示 ### 自定义网站监控 diff --git a/api/bilibili.js b/api/bilibili.js index 3d2b16b..79964b9 100644 --- a/api/bilibili.js +++ b/api/bilibili.js @@ -4,7 +4,7 @@ const { cacheTime, cache } = require('../common/cache'); const { processData } = require('../common/utils'); module.exports = async (req, res) => { - const { id, theme } = req.query; + const { id, theme, lang } = req.query; let key = 'b' + id; let data = cache.get(key); if (!data) { @@ -15,5 +15,5 @@ module.exports = async (req, res) => { processData(data); res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', `public, max-age=${cacheTime}`); - return res.send(renderBilibiliCard(data)); + return res.send(renderBilibiliCard(data, lang)); }; diff --git a/api/csdn.js b/api/csdn.js index ddc330f..bacf00c 100644 --- a/api/csdn.js +++ b/api/csdn.js @@ -4,7 +4,7 @@ const { cacheTime, cache } = require('../common/cache'); const { processData } = require('../common/utils'); module.exports = async (req, res) => { - const { id, theme } = req.query; + const { id, theme, lang } = req.query; let key = 'c' + id; let data = cache.get(key); if (!data) { @@ -15,5 +15,5 @@ module.exports = async (req, res) => { processData(data); res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', `public, max-age=${cacheTime}`); - return res.send(renderCSDNCard(data)); + return res.send(renderCSDNCard(data, lang)); }; diff --git a/api/github.js b/api/github.js index 64ddad9..9ab77a8 100644 --- a/api/github.js +++ b/api/github.js @@ -4,7 +4,7 @@ const { cacheTime, cache } = require('../common/cache'); const { processData } = require('../common/utils'); module.exports = async (req, res) => { - const { username, theme } = req.query; + const { username, theme, lang } = req.query; let key = 'g' + username; let data = cache.get(key); if (!data) { @@ -15,5 +15,5 @@ module.exports = async (req, res) => { processData(data); res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', `public, max-age=${cacheTime}`); - return res.send(renderGitHubCard(data)); + return res.send(renderGitHubCard(data, lang)); }; diff --git a/api/juejin.js b/api/juejin.js index 8d3f812..8bc67e9 100644 --- a/api/juejin.js +++ b/api/juejin.js @@ -4,7 +4,7 @@ const { cacheTime, cache } = require('../common/cache'); const { processData } = require('../common/utils'); module.exports = async (req, res) => { - const { id, theme } = req.query; + const { id, theme, lang } = req.query; let key = 'j' + id; let data = cache.get(key); if (!data) { @@ -15,5 +15,5 @@ module.exports = async (req, res) => { processData(data); res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', `public, max-age=${cacheTime}`); - return res.send(renderJuejinCard(data)); + return res.send(renderJuejinCard(data, lang)); }; diff --git a/api/leetcode.js b/api/leetcode.js index 6d768b5..6953c7b 100644 --- a/api/leetcode.js +++ b/api/leetcode.js @@ -4,7 +4,7 @@ const renderLeetCodeCard = require('../render/leetcode'); const { cache, cacheTime } = require('../common/cache'); module.exports = async (req, res) => { - const { username, cn, theme, cn_username } = req.query; + const { username, cn, theme, cn_username, lang } = req.query; let data = null; if (!cn_username) { if (cn) { @@ -44,5 +44,5 @@ module.exports = async (req, res) => { data.theme = theme; res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', `public, max-age=${cacheTime}`); - return res.send(renderLeetCodeCard(data)); + return res.send(renderLeetCodeCard(data, lang)); }; diff --git a/api/nowcoder.js b/api/nowcoder.js index 866a308..5be2474 100644 --- a/api/nowcoder.js +++ b/api/nowcoder.js @@ -4,7 +4,7 @@ const { cache, cacheTime } = require('../common/cache'); const { processData } = require('../common/utils'); module.exports = async (req, res) => { - const { id, theme } = req.query; + const { id, theme, lang } = req.query; let key = 'n' + id; let data = cache.get(key); if (!data) { @@ -15,5 +15,5 @@ module.exports = async (req, res) => { processData(data); res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', `public, max-age=${cacheTime}`); - return res.send(renderNowCoderCard(data)); + return res.send(renderNowCoderCard(data, lang)); }; diff --git a/api/zhihu.js b/api/zhihu.js index 148f462..018c29d 100644 --- a/api/zhihu.js +++ b/api/zhihu.js @@ -4,7 +4,7 @@ const { cache, cacheTime } = require('../common/cache'); const { processData } = require('../common/utils'); module.exports = async (req, res) => { - const { username, theme } = req.query; + const { username, theme, lang } = req.query; let key = 'z' + username; let data = cache.get(key); if (!data) { @@ -15,5 +15,5 @@ module.exports = async (req, res) => { processData(data); res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Cache-Control', `public, max-age=${cacheTime}`); - return res.send(renderZhihuCard(data)); + return res.send(renderZhihuCard(data, lang)); }; diff --git a/common/utils.js b/common/utils.js index 5709aa8..32b7a68 100644 --- a/common/utils.js +++ b/common/utils.js @@ -34,8 +34,14 @@ const processData = (data) => { } }; +const isEndsWithASCII = (str) => { + if (str.length === 0) return false; + return str.charCodeAt(str.length - 1) <= 127; +}; + module.exports = { mobileConfig, desktopConfig, processData, + isEndsWithASCII, }; diff --git a/render/bilibili.js b/render/bilibili.js index 8e6416a..129c0f8 100644 --- a/render/bilibili.js +++ b/render/bilibili.js @@ -1,25 +1,49 @@ const { constructItem, render } = require('./common'); +const { isEndsWithASCII } = require('../common/utils'); -function renderBilibiliCard(data) { +function renderBilibiliCard(data, lang) { let { name, description, following, fans, likes, level, views, theme } = data; let lengthLimit = 14; if (description.length > lengthLimit) { description = description.substr(0, lengthLimit); description += '...'; } - let items = [ - constructItem(94, 44, `${name}'s Bilibili Stats`, 'title', 18), - constructItem(55, 84, `Followers`, 'label', 13.5), - constructItem(203, 84, `Video Views`, 'label', 13.5), - constructItem(55, 119, `Upvotes`, 'label', 13.5), - constructItem(203, 119, `Bilibili Level`, 'label', 13.5), - constructItem(55, 154, `Signature`, 'label', 13.5), - constructItem(126, 84, `${fans}`, 'value', 15), - constructItem(126, 119, `${likes}`, 'value', 15), - constructItem(289, 84, `${views}`, 'value', 15), - constructItem(289, 119, `LV${level}`, 'value', 15), - constructItem(126, 154, `${description}`, 'value', 13, '', 'YuGothicUI-Regular, Yu Gothic UI') - ]; + let items = []; + switch (lang) { + case 'zh-CN': + if (isEndsWithASCII(name)) { + name += ' '; + } + items = [ + constructItem(94, 44, `${name}的 B 站数据`, 'title', 18), + constructItem(55, 84, `关注数`, 'label', 13.5), + constructItem(203, 84, `播放量`, 'label', 13.5), + constructItem(55, 119, `点赞数`, 'label', 13.5), + constructItem(203, 119, `等级`, 'label', 13.5), + constructItem(55, 154, `签名`, 'label', 13.5), + constructItem(126, 84, `${fans}`, 'value', 15), + constructItem(126, 119, `${likes}`, 'value', 15), + constructItem(289, 84, `${views}`, 'value', 15), + constructItem(289, 119, `LV${level}`, 'value', 15), + constructItem(126, 154, `${description}`, 'value', 13), + ]; + break; + default: + items = [ + constructItem(94, 44, `${name}'s Bilibili Stats`, 'title', 18), + constructItem(55, 84, `Followers`, 'label', 13.5), + constructItem(203, 84, `Video Views`, 'label', 13.5), + constructItem(55, 119, `Upvotes`, 'label', 13.5), + constructItem(203, 119, `Bilibili Level`, 'label', 13.5), + constructItem(55, 154, `Signature`, 'label', 13.5), + constructItem(126, 84, `${fans}`, 'value', 15), + constructItem(126, 119, `${likes}`, 'value', 15), + constructItem(289, 84, `${views}`, 'value', 15), + constructItem(289, 119, `LV${level}`, 'value', 15), + constructItem(126, 154, `${description}`, 'value', 13), + ]; + break; + } return render(items, theme); } diff --git a/render/csdn.js b/render/csdn.js index c9ac97c..a73fb0e 100644 --- a/render/csdn.js +++ b/render/csdn.js @@ -1,23 +1,48 @@ const { render, constructItem } = require('./common'); +const { isEndsWithASCII } = require('../common/utils'); -function renderCSDNCard(data) { +function renderCSDNCard(data, lang) { let { name, articles, fans, likes, replies, views, credit, theme } = data; - - let items = [ - constructItem(97, 44, `${name}'s CSDN Stats`, 'title', 18), - constructItem(63, 83, `Articles`, 'label', 13.5), - constructItem(63, 120, `Fans`, 'label', 13.5), - constructItem(63, 157, `Likes`, 'label', 13.5), - constructItem(220, 83, `Replies`, 'label', 13.5), - constructItem(220, 120, `Views`, 'label', 13.5), - constructItem(220, 157, `Credit`, 'label', 13.5), - constructItem(134, 83, `${articles}`, 'value', 15), - constructItem(134, 120, `${fans}`, 'value', 15), - constructItem(134, 157, `${likes}`, 'value', 15), - constructItem(295, 83, `${replies}`, 'value', 15), - constructItem(295, 120, `${views}`, 'value', 15), - constructItem(295, 157, `${credit}`, 'value', 15) - ]; + let items = []; + switch (lang) { + case 'zh-CN': + if (isEndsWithASCII(name)) { + name += ' '; + } + items = [ + constructItem(97, 44, `${name}的 CSDN 数据`, 'title', 18), + constructItem(63, 83, `原创`, 'label', 13.5), + constructItem(63, 120, `粉丝`, 'label', 13.5), + constructItem(63, 157, `获赞`, 'label', 13.5), + constructItem(220, 83, `评论`, 'label', 13.5), + constructItem(220, 120, `访问`, 'label', 13.5), + constructItem(220, 157, `积分`, 'label', 13.5), + constructItem(134, 83, `${articles}`, 'value', 15), + constructItem(134, 120, `${fans}`, 'value', 15), + constructItem(134, 157, `${likes}`, 'value', 15), + constructItem(295, 83, `${replies}`, 'value', 15), + constructItem(295, 120, `${views}`, 'value', 15), + constructItem(295, 157, `${credit}`, 'value', 15), + ]; + break; + default: + items = [ + constructItem(97, 44, `${name}'s CSDN Stats`, 'title', 18), + constructItem(63, 83, `Articles`, 'label', 13.5), + constructItem(63, 120, `Fans`, 'label', 13.5), + constructItem(63, 157, `Likes`, 'label', 13.5), + constructItem(220, 83, `Replies`, 'label', 13.5), + constructItem(220, 120, `Views`, 'label', 13.5), + constructItem(220, 157, `Credit`, 'label', 13.5), + constructItem(134, 83, `${articles}`, 'value', 15), + constructItem(134, 120, `${fans}`, 'value', 15), + constructItem(134, 157, `${likes}`, 'value', 15), + constructItem(295, 83, `${replies}`, 'value', 15), + constructItem(295, 120, `${views}`, 'value', 15), + constructItem(295, 157, `${credit}`, 'value', 15), + ]; + break; + } return render(items, theme); } diff --git a/render/github.js b/render/github.js index 21d5634..4dc8f43 100644 --- a/render/github.js +++ b/render/github.js @@ -1,7 +1,8 @@ const { constructItem, render } = require('./common'); +const { isEndsWithASCII } = require('../common/utils'); -function renderGitHubCard(data) { - const { +function renderGitHubCard(data, lang) { + let { name, followers, stars, @@ -11,24 +12,49 @@ function renderGitHubCard(data) { following, theme, issues, - gists + gists, } = data; - let items = [ - constructItem(97, 44, `${name}'s GitHub Stats`, 'title', 18), - constructItem(63, 83, `Stars`, 'label', 13.5), - constructItem(63, 120, `Repos`, 'label', 13.5), - constructItem(63, 157, `Gists`, 'label', 13.5), - constructItem(220, 83, `Followers`, 'label', 13.5), - constructItem(220, 120, `Following`, 'label', 13.5), - constructItem(220, 157, `Forked`, 'label', 13.5), - constructItem(134, 83, `${stars}`, 'value', 15), - constructItem(134, 120, `${repos}`, 'value', 15), - constructItem(134, 157, `${gists}`, 'value', 15), - constructItem(295, 83, `${followers}`, 'value', 15), - constructItem(295, 120, `${following}`, 'value', 15), - constructItem(295, 157, `${forks}`, 'value', 15) - ]; + let items = []; + switch (lang) { + case 'zh-CN': + if (isEndsWithASCII(name)) { + name += ' '; + } + items = [ + constructItem(97, 44, `${name}的 GitHub 数据`, 'title', 18), + constructItem(63, 83, `星标总数`, 'label', 13.5), + constructItem(63, 120, `代码仓库`, 'label', 13.5), + constructItem(63, 157, `代码片段`, 'label', 13.5), + constructItem(220, 83, `粉丝总数`, 'label', 13.5), + constructItem(220, 120, `追踪数量`, 'label', 13.5), + constructItem(220, 157, `复刻数量`, 'label', 13.5), + constructItem(134, 83, `${stars}`, 'value', 15), + constructItem(134, 120, `${repos}`, 'value', 15), + constructItem(134, 157, `${gists}`, 'value', 15), + constructItem(295, 83, `${followers}`, 'value', 15), + constructItem(295, 120, `${following}`, 'value', 15), + constructItem(295, 157, `${forks}`, 'value', 15), + ]; + break; + default: + items = [ + constructItem(97, 44, `${name}'s GitHub Stats`, 'title', 18), + constructItem(63, 83, `Stars`, 'label', 13.5), + constructItem(63, 120, `Repos`, 'label', 13.5), + constructItem(63, 157, `Gists`, 'label', 13.5), + constructItem(220, 83, `Followers`, 'label', 13.5), + constructItem(220, 120, `Following`, 'label', 13.5), + constructItem(220, 157, `Forked`, 'label', 13.5), + constructItem(134, 83, `${stars}`, 'value', 15), + constructItem(134, 120, `${repos}`, 'value', 15), + constructItem(134, 157, `${gists}`, 'value', 15), + constructItem(295, 83, `${followers}`, 'value', 15), + constructItem(295, 120, `${following}`, 'value', 15), + constructItem(295, 157, `${forks}`, 'value', 15), + ]; + break; + } return render(items, theme); } diff --git a/render/juejin.js b/render/juejin.js index 10de6ba..a032982 100644 --- a/render/juejin.js +++ b/render/juejin.js @@ -1,6 +1,7 @@ const { render, constructItem } = require('./common'); +const { isEndsWithASCII } = require('../common/utils'); -function renderJuejinCard(data) { +function renderJuejinCard(data, lang) { let { user_name, description, // 描述 @@ -8,7 +9,7 @@ function renderJuejinCard(data) { got_digg_count, // 获得点赞 article_count, // 文章数 got_view_count, // 文章被阅读 - theme + theme, } = data; let lengthLimit = 14; if (description.length > lengthLimit) { @@ -16,19 +17,42 @@ function renderJuejinCard(data) { description += '...'; } - let items = [ - constructItem(94, 44, `${user_name}'s Juejin Stats`, 'title', 18), - constructItem(55, 84, `Followers`, 'label', 13.5), - constructItem(203, 84, `Likes`, 'label', 13.5), - constructItem(55, 119, `Articles`, 'label', 13.5), - constructItem(203, 119, `Article Views`, 'label', 13.5), - constructItem(55, 154, `Signature`, 'label', 13.5), - constructItem(126, 84, `${follower_count}`, 'value', 15), - constructItem(126, 119, `${article_count}`, 'value', 15), - constructItem(289, 84, `${got_digg_count}`, 'value', 15), - constructItem(289, 119, `${got_view_count}`, 'value', 15), - constructItem(126, 154, `${description}`, 'value', 13, '', 'YuGothicUI-Regular, Yu Gothic UI') - ]; + let items = []; + switch (lang) { + case 'zh-CN': + if (isEndsWithASCII(user_name)) { + user_name += ' '; + } + items = [ + constructItem(94, 44, `${user_name}的掘金数据`, 'title', 18), + constructItem(55, 84, `关注者`, 'label', 13.5), + constructItem(203, 84, `点赞数`, 'label', 13.5), + constructItem(55, 119, `文章数`, 'label', 13.5), + constructItem(203, 119, `阅读量`, 'label', 13.5), + constructItem(55, 154, `签名`, 'label', 13.5), + constructItem(126, 84, `${follower_count}`, 'value', 15), + constructItem(126, 119, `${article_count}`, 'value', 15), + constructItem(289, 84, `${got_digg_count}`, 'value', 15), + constructItem(289, 119, `${got_view_count}`, 'value', 15), + constructItem(126, 154, `${description}`, 'value', 13), + ]; + break; + default: + items = [ + constructItem(94, 44, `${user_name}'s Juejin Stats`, 'title', 18), + constructItem(55, 84, `Followers`, 'label', 13.5), + constructItem(203, 84, `Likes`, 'label', 13.5), + constructItem(55, 119, `Articles`, 'label', 13.5), + constructItem(203, 119, `Article Views`, 'label', 13.5), + constructItem(55, 154, `Signature`, 'label', 13.5), + constructItem(126, 84, `${follower_count}`, 'value', 15), + constructItem(126, 119, `${article_count}`, 'value', 15), + constructItem(289, 84, `${got_digg_count}`, 'value', 15), + constructItem(289, 119, `${got_view_count}`, 'value', 15), + constructItem(126, 154, `${description}`, 'value', 13), + ]; + break; + } return render(items, theme); } diff --git a/render/leetcode.js b/render/leetcode.js index 1fc6413..f45e6f5 100644 --- a/render/leetcode.js +++ b/render/leetcode.js @@ -1,7 +1,8 @@ const { render, constructItem } = require('./common'); +const { isEndsWithASCII } = require('../common/utils'); -function renderLeetCodeCard(data) { - const { +function renderLeetCodeCard(data, lang) { + let { name, easy_solved, medium_solved, @@ -9,21 +10,44 @@ function renderLeetCodeCard(data) { total_solved, acceptance, star_rating, - theme + theme, } = data; - let items = [ - constructItem(82, 44, `${name}'s LeetCode Stats`, 'title', 18), - constructItem(55, 169, `Easy`, 'label', 12, '#43a047'), - constructItem(154, 169, `Medium`, 'label', 12, '#fb8c00'), - constructItem(275, 169, `Hard`, 'label', 12, '#e91e63'), - constructItem(234, 121, `${acceptance}`, 'value', 25), - constructItem(232, 83, `Acceptance`, 'label', 13.5), - constructItem(55, 83, `Problems Solved`, 'label', 13.5), - constructItem(85, 121, `${total_solved}`, 'value', 25), - constructItem(85, 169, `${easy_solved}`, 'value', 12), - constructItem(205, 169, `${medium_solved}`, 'value', 12), - constructItem(308, 169, `${hard_solved}`, 'value', 12), - ]; + let items = []; + switch (lang) { + case 'zh-CN': + if (isEndsWithASCII(name)) { + name += ' '; + } + items = [ + constructItem(82, 44, `${name}的力扣数据`, 'title', 18), + constructItem(55, 169, `简单`, 'label', 12, '#43a047'), + constructItem(154, 169, `中等`, 'label', 12, '#fb8c00'), + constructItem(275, 169, `困难`, 'label', 12, '#e91e63'), + constructItem(234, 121, `${acceptance}`, 'value', 25), + constructItem(245, 83, `接受率`, 'label', 13.5), + constructItem(78, 83, `解决问题`, 'label', 13.5), + constructItem(85, 121, `${total_solved}`, 'value', 25), + constructItem(85, 169, `${easy_solved}`, 'value', 12), + constructItem(205, 169, `${medium_solved}`, 'value', 12), + constructItem(308, 169, `${hard_solved}`, 'value', 12), + ]; + break; + default: + items = [ + constructItem(82, 44, `${name}'s LeetCode Stats`, 'title', 18), + constructItem(55, 169, `Easy`, 'label', 12, '#43a047'), + constructItem(154, 169, `Medium`, 'label', 12, '#fb8c00'), + constructItem(275, 169, `Hard`, 'label', 12, '#e91e63'), + constructItem(234, 121, `${acceptance}`, 'value', 25), + constructItem(232, 83, `Acceptance`, 'label', 13.5), + constructItem(55, 83, `Problems Solved`, 'label', 13.5), + constructItem(85, 121, `${total_solved}`, 'value', 25), + constructItem(85, 169, `${easy_solved}`, 'value', 12), + constructItem(205, 169, `${medium_solved}`, 'value', 12), + constructItem(308, 169, `${hard_solved}`, 'value', 12), + ]; + break; + } return render(items, theme); } diff --git a/render/nowcoder.js b/render/nowcoder.js index bf22846..771261d 100644 --- a/render/nowcoder.js +++ b/render/nowcoder.js @@ -1,32 +1,49 @@ const { render, constructItem } = require('./common'); +const { isEndsWithASCII } = require('../common/utils'); -function renderNowCoderCard(data) { - const { - name, - fans, - score, - likes, - questionAC, - codingAC, - level, - theme - } = data; +function renderNowCoderCard(data, lang) { + let { name, fans, score, likes, questionAC, codingAC, level, theme } = data; - let items = [ - constructItem(97, 44, `${name}'s NowCoder Stats`, 'title', 18), - constructItem(63, 83, `Followers`, 'label', 13.5), - constructItem(63, 120, `Likes`, 'label', 13.5), - constructItem(63, 157, `Score`, 'label', 13.5), - constructItem(220, 83, `Level`, 'label', 13.5), - constructItem(220, 120, `Questions`, 'label', 13.5), - constructItem(220, 157, `Coding`, 'label', 13.5), - constructItem(134, 83, `${fans}`, 'value', 15), - constructItem(134, 120, `${likes}`, 'value', 15), - constructItem(134, 157, `${score}`, 'value', 15), - constructItem(295, 83, `${level}`, 'value', 15), - constructItem(295, 120, `${questionAC}`, 'value', 15), - constructItem(295, 157, `${codingAC}`, 'value', 15) - ]; + let items = []; + switch (lang) { + case 'zh-CN': + if (isEndsWithASCII(name)) { + name += ' '; + } + items = [ + constructItem(97, 44, `${name}的牛客数据`, 'title', 18), + constructItem(63, 83, `粉丝`, 'label', 13.5), + constructItem(63, 120, `获赞`, 'label', 13.5), + constructItem(63, 157, `分数`, 'label', 13.5), + constructItem(220, 83, `等级`, 'label', 13.5), + constructItem(220, 120, `问题`, 'label', 13.5), + constructItem(220, 157, `代码`, 'label', 13.5), + constructItem(134, 83, `${fans}`, 'value', 15), + constructItem(134, 120, `${likes}`, 'value', 15), + constructItem(134, 157, `${score}`, 'value', 15), + constructItem(295, 83, `${level}`, 'value', 15), + constructItem(295, 120, `${questionAC}`, 'value', 15), + constructItem(295, 157, `${codingAC}`, 'value', 15), + ]; + break; + default: + items = [ + constructItem(97, 44, `${name}'s NowCoder Stats`, 'title', 18), + constructItem(63, 83, `Followers`, 'label', 13.5), + constructItem(63, 120, `Likes`, 'label', 13.5), + constructItem(63, 157, `Score`, 'label', 13.5), + constructItem(220, 83, `Level`, 'label', 13.5), + constructItem(220, 120, `Questions`, 'label', 13.5), + constructItem(220, 157, `Coding`, 'label', 13.5), + constructItem(134, 83, `${fans}`, 'value', 15), + constructItem(134, 120, `${likes}`, 'value', 15), + constructItem(134, 157, `${score}`, 'value', 15), + constructItem(295, 83, `${level}`, 'value', 15), + constructItem(295, 120, `${questionAC}`, 'value', 15), + constructItem(295, 157, `${codingAC}`, 'value', 15), + ]; + break; + } return render(items, theme); } diff --git a/render/zhihu.js b/render/zhihu.js index 3d0dfc1..41cd5a0 100644 --- a/render/zhihu.js +++ b/render/zhihu.js @@ -1,7 +1,8 @@ const { constructItem, render } = require('./common'); +const { isEndsWithASCII } = require('../common/utils'); -function renderZhihuCard(data) { - const { +function renderZhihuCard(data, lang) { + let { name, description, follower_count, @@ -10,24 +11,49 @@ function renderZhihuCard(data) { thanked_count, question_count, articles_count, - theme + theme, } = data; - let items = [ - constructItem(97, 44, `${name}'s Zhihu Stats`, 'title', 18), - constructItem(63, 83, `Followers`, 'label', 13.5), - constructItem(63, 120, `Upvotes`, 'label', 13.5), - constructItem(63, 157, `Likes`, 'label', 13.5), - constructItem(220, 83, `Questions`, 'label', 13.5), - constructItem(220, 120, `Answers`, 'label', 13.5), - constructItem(220, 157, `Articles`, 'label', 13.5), - constructItem(134, 83, `${follower_count}`, 'value', 15), - constructItem(134, 120, `${voteup_count}`, 'value', 15), - constructItem(134, 157, `${thanked_count}`, 'value', 15), - constructItem(295, 83, `${question_count}`, 'value', 15), - constructItem(295, 120, `${answer_count}`, 'value', 15), - constructItem(295, 157, `${articles_count}`, 'value', 15), - ]; + let items = []; + switch (lang) { + case 'zh-CN': + if (isEndsWithASCII(name)) { + name += ' '; + } + items = [ + constructItem(97, 44, `${name}的知乎数据`, 'title', 18), + constructItem(63, 83, `关注者`, 'label', 13.5), + constructItem(63, 120, `赞同数`, 'label', 13.5), + constructItem(63, 157, `喜欢数`, 'label', 13.5), + constructItem(220, 83, `问题数`, 'label', 13.5), + constructItem(220, 120, `回答数`, 'label', 13.5), + constructItem(220, 157, `文章数`, 'label', 13.5), + constructItem(134, 83, `${follower_count}`, 'value', 15), + constructItem(134, 120, `${voteup_count}`, 'value', 15), + constructItem(134, 157, `${thanked_count}`, 'value', 15), + constructItem(295, 83, `${question_count}`, 'value', 15), + constructItem(295, 120, `${answer_count}`, 'value', 15), + constructItem(295, 157, `${articles_count}`, 'value', 15), + ]; + break; + default: + items = [ + constructItem(97, 44, `${name}'s Zhihu Stats`, 'title', 18), + constructItem(63, 83, `Followers`, 'label', 13.5), + constructItem(63, 120, `Upvotes`, 'label', 13.5), + constructItem(63, 157, `Likes`, 'label', 13.5), + constructItem(220, 83, `Questions`, 'label', 13.5), + constructItem(220, 120, `Answers`, 'label', 13.5), + constructItem(220, 157, `Articles`, 'label', 13.5), + constructItem(134, 83, `${follower_count}`, 'value', 15), + constructItem(134, 120, `${voteup_count}`, 'value', 15), + constructItem(134, 157, `${thanked_count}`, 'value', 15), + constructItem(295, 83, `${question_count}`, 'value', 15), + constructItem(295, 120, `${answer_count}`, 'value', 15), + constructItem(295, 157, `${articles_count}`, 'value', 15), + ]; + break; + } return render(items, theme); }