From e09354a0f0f9d21a3e890d60dfa9d03482330316 Mon Sep 17 00:00:00 2001 From: HcGys <370379459@qq.com> Date: Wed, 22 May 2024 23:57:29 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/utils/highlight.js | 14 +++++++--- src/client/utils/i18n/i18n.js | 13 +++++++++ src/client/view/components/TkAdminComment.vue | 2 +- src/client/view/components/TkAdminConfig.vue | 1 + src/client/view/components/TkComment.vue | 2 +- src/client/view/components/TkComments.vue | 27 +++++++++++++++++++ src/client/view/components/TkSubmit.vue | 2 +- src/server/function/twikoo/utils/index.js | 1 + 8 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/client/utils/highlight.js b/src/client/utils/highlight.js index 3a958b671..72fd8a309 100644 --- a/src/client/utils/highlight.js +++ b/src/client/utils/highlight.js @@ -4,7 +4,7 @@ const PRISM_CDN = 'https://cdn.staticfile.net/prism/1.28.0' let Prism let cssEl -const renderCode = (el, theme) => { +const renderCode = (el, theme, plugins) => { const prismCdn = (app && app.$twikoo.prismCdn) ? app.$twikoo.prismCdn : PRISM_CDN window.Prism = window.Prism || {} window.Prism.manual = true @@ -12,8 +12,16 @@ const renderCode = (el, theme) => { Prism = require('prismjs') require('prismjs/plugins/autoloader/prism-autoloader') Prism.plugins.autoloader.languages_path = `${prismCdn}/components/` - // require('prismjs/plugins/toolbar/prism-toolbar') - // require('prismjs/plugins/show-language/prism-show-language') + if (plugins) { + require('prismjs/plugins/toolbar/prism-toolbar') + plugins.split(',').map(item => {return item.trim()} ).forEach(p => { + if (p === 'showLanguage') { + require('prismjs/plugins/show-language/prism-show-language') + } else if (p === 'copyButton') { + require('prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard') + } + }); + } } loadCss(theme, prismCdn) Prism.highlightAllUnder(el) diff --git a/src/client/utils/i18n/i18n.js b/src/client/utils/i18n/i18n.js index ab88c8529..1f77ce361 100644 --- a/src/client/utils/i18n/i18n.js +++ b/src/client/utils/i18n/i18n.js @@ -81,6 +81,11 @@ const highlightThemes = [ 'twilight' ].map(s => `"${s}"`) +const highlightPlugins = [ + 'showLanguage', + 'copyButton' +].map(s => `"${s}"`) + const imageBedServices = [ 'qcloud', '7bu', @@ -455,6 +460,14 @@ export default { `Кодни таъкидлаш мавзуси. Қуйидагилардан танланг: ${highlightThemes.join(', ')}. Олдиндан кўриш учун https://prismjs.com сайтига ташриф буюринг. Агар мавзуингиз кодни ажратиб кўрсатишга зид бўлса, уни «Ҳеч» га ўрнатинг. Стандарт: йўқ.`, `コードハイライトのテーマ、選択肢:${highlightThemes.join('、')}、テーマの効果をプレビューするには https://prismjs.com を訪問してください。テーマとコードハイライトに競合がある場合、noneに設定してください。デフォルト:none` ], + [S.ACI + '_HIGHLIGHT_PLUGIN']: [ + `代码高亮插件,可选:${highlightPlugins.join('、')},分别表示:展示代码语言、展示代码拷贝按钮。可以同时设置多个选项,如果想要不添加任何代码高亮插件,请设为 none。默认:none。`, + `代碼高亮插件,可選:${highlightPlugins.join('、')},分別表示:展示代碼語言、展示代碼拷貝按鈕。可以同時設置多個選項,如果想要不添加任何代碼高亮插件,請設為 none。預設:none。`, + `代碼高亮外掛程式,可選:${highlightPlugins.join('、')},分別表示:展示代碼語言、展示代碼拷貝按鈕。 可以同時設置多個選項,如果想要不添加任何代碼高亮外掛程式,請設定為 none。預設:none。`, + `Code highlight plug-in, optional: ${highlightPlugins.join(', ')}, respectively: show code language, show code copy button. Multiple options can be set at the same time, if you want to add no code highlighting plug-ins, please set it to none. Default: none. `, + `Плагин подсветки кода, опционально: ${highlightPlugins.join(',')}, соответственно: показывать язык кода, показывать кнопку копирования кода. Вы можете установить несколько опций одновременно, если вы хотите не добавлять плагин подсветки кода, установите значение none. по умолчанию: none.`, + `コード・ハイライト・プラグイン、オプション: ${highlightPlugins.join(',')}, それぞれ: コード言語の表示、コード・コピー・ボタンの表示。 複数のオプションを同時に設定できますが、コード・ハイライト・プラグインを追加したくない場合は、noneに設定してください。` + ], [S.ACI + '_IMAGE_CDN']: [ `插入图片所使用的图床,目前支持:${imageBedServices.join('、')}`, `插入圖片所使用的圖床,目前支持:${imageBedServices.join('、')}`, diff --git a/src/client/view/components/TkAdminComment.vue b/src/client/view/components/TkAdminComment.vue index a07b04bd7..e4d39e3c4 100644 --- a/src/client/view/components/TkAdminComment.vue +++ b/src/client/view/components/TkAdminComment.vue @@ -174,7 +174,7 @@ export default { }, highlightCode () { if (this.serverConfig.HIGHLIGHT === 'true') { - renderCode(this.$refs['comment-list'], this.serverConfig.HIGHLIGHT_THEME) + renderCode(this.$refs['comment-list'], this.serverConfig.HIGHLIGHT_THEME, this.serverConfig.HIGHLIGHT_PLUGIN) } } }, diff --git a/src/client/view/components/TkAdminConfig.vue b/src/client/view/components/TkAdminConfig.vue index 1a46b5f7e..037792b98 100644 --- a/src/client/view/components/TkAdminConfig.vue +++ b/src/client/view/components/TkAdminConfig.vue @@ -76,6 +76,7 @@ export default { { key: 'EMOTION_CDN', desc: t('ADMIN_CONFIG_ITEM_EMOTION_CDN'), ph: '', value: '' }, { key: 'HIGHLIGHT', desc: t('ADMIN_CONFIG_ITEM_HIGHLIGHT'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}false`, value: '' }, { key: 'HIGHLIGHT_THEME', desc: t('ADMIN_CONFIG_ITEM_HIGHLIGHT_THEME'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}tomorrow`, value: '' }, + { key: 'HIGHLIGHT_PLUGIN', desc: t('ADMIN_CONFIG_ITEM_HIGHLIGHT_PLUGIN'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}showLanguage`, value: '' }, { key: 'LIGHTBOX', desc: t('ADMIN_CONFIG_ITEM_LIGHTBOX'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}true`, value: '' } ] }, diff --git a/src/client/view/components/TkComment.vue b/src/client/view/components/TkComment.vue index 8a125e031..be692689b 100644 --- a/src/client/view/components/TkComment.vue +++ b/src/client/view/components/TkComment.vue @@ -334,7 +334,7 @@ export default { handler: function (highlight) { if (highlight === 'true') { this.$nextTick(() => { - renderCode(this.$refs.comment, this.config.HIGHLIGHT_THEME) + renderCode(this.$refs.comment, this.config.HIGHLIGHT_THEME, this.serverConfig.HIGHLIGHT_PLUGIN) }) } }, diff --git a/src/client/view/components/TkComments.vue b/src/client/view/components/TkComments.vue index f4e9cef55..2147df4a7 100644 --- a/src/client/view/components/TkComments.vue +++ b/src/client/view/components/TkComments.vue @@ -161,4 +161,31 @@ export default { cursor: pointer; color: #409eff; } +div.code-toolbar { + position: relative; + border-radius: .3em +} +div.code-toolbar>.toolbar { + position: absolute; + right: 4px; + top: 4px; + font-size: .8125rem; + font-weight: 500; + display: flex; +} +div.code-toolbar>.toolbar>.toolbar-item { + margin-left: .3em +} +div.code-toolbar>.toolbar>.toolbar-item>a, +div.code-toolbar>.toolbar>.toolbar-item>button, +div.code-toolbar>.toolbar>.toolbar-item>span { + padding: 2px 4px; + border-radius: .3em; +} +div.code-toolbar>.toolbar>.toolbar-item>button { + border: 1px solid rgba(128, 128, 128, 0.31); +} +div.code-toolbar>.toolbar>.toolbar-item>button:hover { + cursor: pointer; +} diff --git a/src/client/view/components/TkSubmit.vue b/src/client/view/components/TkSubmit.vue index 70f960ba9..fef2fad7b 100644 --- a/src/client/view/components/TkSubmit.vue +++ b/src/client/view/components/TkSubmit.vue @@ -202,7 +202,7 @@ export default { renderLinks(this.$refs['comment-preview']) renderMath(this.$refs['comment-preview'], this.$twikoo.katex) if (this.config.HIGHLIGHT === 'true') { - renderCode(this.$refs['comment-preview'], this.config.HIGHLIGHT_THEME) + renderCode(this.$refs['comment-preview'], this.config.HIGHLIGHT_THEME, this.serverConfig.HIGHLIGHT_PLUGIN) } }) } diff --git a/src/server/function/twikoo/utils/index.js b/src/server/function/twikoo/utils/index.js index eab385c12..1390f231f 100644 --- a/src/server/function/twikoo/utils/index.js +++ b/src/server/function/twikoo/utils/index.js @@ -296,6 +296,7 @@ const fn = { HIDE_ADMIN_CRYPT: config.HIDE_ADMIN_CRYPT, HIGHLIGHT: config.HIGHLIGHT || 'true', HIGHLIGHT_THEME: config.HIGHLIGHT_THEME, + HIGHLIGHT_PLUGIN: config.HIGHLIGHT_PLUGIN, LIMIT_LENGTH: config.LIMIT_LENGTH, TURNSTILE_SITE_KEY: config.TURNSTILE_SITE_KEY } From 3646b6b4fdf4410b831558b206f88b00ecd0410a Mon Sep 17 00:00:00 2001 From: HcGys <370379459@qq.com> Date: Thu, 23 May 2024 00:08:47 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/utils/highlight.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/utils/highlight.js b/src/client/utils/highlight.js index 72fd8a309..265d9df6c 100644 --- a/src/client/utils/highlight.js +++ b/src/client/utils/highlight.js @@ -14,13 +14,13 @@ const renderCode = (el, theme, plugins) => { Prism.plugins.autoloader.languages_path = `${prismCdn}/components/` if (plugins) { require('prismjs/plugins/toolbar/prism-toolbar') - plugins.split(',').map(item => {return item.trim()} ).forEach(p => { + plugins.split(',').map(item => { return item.trim() }).forEach(p => { if (p === 'showLanguage') { require('prismjs/plugins/show-language/prism-show-language') } else if (p === 'copyButton') { require('prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard') } - }); + }) } } loadCss(theme, prismCdn) From 6c28fccb50fce1a728230d36d7dcfde63061e9e8 Mon Sep 17 00:00:00 2001 From: HcGys <370379459@qq.com> Date: Fri, 24 May 2024 14:29:18 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/view/components/TkComment.vue | 4 ++-- src/client/view/components/TkSubmit.vue | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/view/components/TkComment.vue b/src/client/view/components/TkComment.vue index be692689b..163b0fb2a 100644 --- a/src/client/view/components/TkComment.vue +++ b/src/client/view/components/TkComment.vue @@ -198,7 +198,7 @@ export default { } }, showContentExpandIfNeed () { - this.hasContentExpand = this.$refs['tk-content'].scrollHeight > 500 + this.hasContentExpand = this.hasContentExpand || this.$refs['tk-content'].scrollHeight > 500 // 如果已经折叠就不再判断 主要是为了防止图片在onload之前就已经折叠而导致图片在onload之后取消折叠 }, showContentExpandIfNeedAfterImagesLoaded () { this.$refs['tk-content'].querySelectorAll('img').forEach((imgEl) => { @@ -334,7 +334,7 @@ export default { handler: function (highlight) { if (highlight === 'true') { this.$nextTick(() => { - renderCode(this.$refs.comment, this.config.HIGHLIGHT_THEME, this.serverConfig.HIGHLIGHT_PLUGIN) + renderCode(this.$refs.comment, this.config.HIGHLIGHT_THEME, this.config.HIGHLIGHT_PLUGIN) }) } }, diff --git a/src/client/view/components/TkSubmit.vue b/src/client/view/components/TkSubmit.vue index fef2fad7b..511f5f7cd 100644 --- a/src/client/view/components/TkSubmit.vue +++ b/src/client/view/components/TkSubmit.vue @@ -202,7 +202,7 @@ export default { renderLinks(this.$refs['comment-preview']) renderMath(this.$refs['comment-preview'], this.$twikoo.katex) if (this.config.HIGHLIGHT === 'true') { - renderCode(this.$refs['comment-preview'], this.config.HIGHLIGHT_THEME, this.serverConfig.HIGHLIGHT_PLUGIN) + renderCode(this.$refs['comment-preview'], this.config.HIGHLIGHT_THEME, this.config.HIGHLIGHT_PLUGIN) } }) } From 007fa17b902fe3bb0ecbd1faa8ec93674e17bc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= <93642775+HcGys@users.noreply.github.com> Date: Fri, 24 May 2024 17:09:08 +0800 Subject: [PATCH 04/10] Update src/client/view/components/TkComments.vue Co-authored-by: iMaeGoo --- src/client/view/components/TkComments.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/view/components/TkComments.vue b/src/client/view/components/TkComments.vue index 2147df4a7..0dcfec6a4 100644 --- a/src/client/view/components/TkComments.vue +++ b/src/client/view/components/TkComments.vue @@ -161,7 +161,7 @@ export default { cursor: pointer; color: #409eff; } -div.code-toolbar { +.twikoo div.code-toolbar { position: relative; border-radius: .3em } From 76476b9251e7944ff3c394cb69a18b1634a8d2b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= <93642775+HcGys@users.noreply.github.com> Date: Fri, 24 May 2024 17:09:29 +0800 Subject: [PATCH 05/10] Update src/client/view/components/TkComments.vue Co-authored-by: iMaeGoo --- src/client/view/components/TkComments.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/view/components/TkComments.vue b/src/client/view/components/TkComments.vue index 0dcfec6a4..a228b754a 100644 --- a/src/client/view/components/TkComments.vue +++ b/src/client/view/components/TkComments.vue @@ -173,7 +173,7 @@ div.code-toolbar>.toolbar { font-weight: 500; display: flex; } -div.code-toolbar>.toolbar>.toolbar-item { +.twikoo div.code-toolbar>.toolbar>.toolbar-item { margin-left: .3em } div.code-toolbar>.toolbar>.toolbar-item>a, From 9436eb79696459638c909d7f848c9335ccaed6b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= <93642775+HcGys@users.noreply.github.com> Date: Fri, 24 May 2024 17:09:52 +0800 Subject: [PATCH 06/10] Update src/client/view/components/TkComments.vue Co-authored-by: iMaeGoo --- src/client/view/components/TkComments.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/view/components/TkComments.vue b/src/client/view/components/TkComments.vue index a228b754a..381b67f4f 100644 --- a/src/client/view/components/TkComments.vue +++ b/src/client/view/components/TkComments.vue @@ -176,9 +176,9 @@ div.code-toolbar>.toolbar { .twikoo div.code-toolbar>.toolbar>.toolbar-item { margin-left: .3em } -div.code-toolbar>.toolbar>.toolbar-item>a, -div.code-toolbar>.toolbar>.toolbar-item>button, -div.code-toolbar>.toolbar>.toolbar-item>span { +.twikoo div.code-toolbar>.toolbar>.toolbar-item>a, +.twikoo div.code-toolbar>.toolbar>.toolbar-item>button, +.twikoo div.code-toolbar>.toolbar>.toolbar-item>span { padding: 2px 4px; border-radius: .3em; } From 89041c9f7bcf3da1e5f96f896510769325e7ebe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= <93642775+HcGys@users.noreply.github.com> Date: Fri, 24 May 2024 17:10:00 +0800 Subject: [PATCH 07/10] Update src/client/view/components/TkComments.vue Co-authored-by: iMaeGoo --- src/client/view/components/TkComments.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/view/components/TkComments.vue b/src/client/view/components/TkComments.vue index 381b67f4f..71f0ce333 100644 --- a/src/client/view/components/TkComments.vue +++ b/src/client/view/components/TkComments.vue @@ -182,7 +182,7 @@ div.code-toolbar>.toolbar { padding: 2px 4px; border-radius: .3em; } -div.code-toolbar>.toolbar>.toolbar-item>button { +.twikoo div.code-toolbar>.toolbar>.toolbar-item>button { border: 1px solid rgba(128, 128, 128, 0.31); } div.code-toolbar>.toolbar>.toolbar-item>button:hover { From e0cd97183c04d11bb4cf08f53aef20f4f0394259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= <93642775+HcGys@users.noreply.github.com> Date: Fri, 24 May 2024 17:10:11 +0800 Subject: [PATCH 08/10] Update src/client/view/components/TkComments.vue Co-authored-by: iMaeGoo --- src/client/view/components/TkComments.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/view/components/TkComments.vue b/src/client/view/components/TkComments.vue index 71f0ce333..7717caf5b 100644 --- a/src/client/view/components/TkComments.vue +++ b/src/client/view/components/TkComments.vue @@ -185,7 +185,7 @@ div.code-toolbar>.toolbar { .twikoo div.code-toolbar>.toolbar>.toolbar-item>button { border: 1px solid rgba(128, 128, 128, 0.31); } -div.code-toolbar>.toolbar>.toolbar-item>button:hover { +.twikoo div.code-toolbar>.toolbar>.toolbar-item>button:hover { cursor: pointer; } From 17f3630cd23b317c8c91002941220371c0ee7e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= <93642775+HcGys@users.noreply.github.com> Date: Fri, 24 May 2024 17:10:24 +0800 Subject: [PATCH 09/10] Update src/client/view/components/TkComments.vue Co-authored-by: iMaeGoo --- src/client/view/components/TkComments.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/view/components/TkComments.vue b/src/client/view/components/TkComments.vue index 7717caf5b..f97688784 100644 --- a/src/client/view/components/TkComments.vue +++ b/src/client/view/components/TkComments.vue @@ -165,7 +165,7 @@ export default { position: relative; border-radius: .3em } -div.code-toolbar>.toolbar { +.twikoo div.code-toolbar>.toolbar { position: absolute; right: 4px; top: 4px; From b26874ab5341945c54a2cc6475f6150600b6150a Mon Sep 17 00:00:00 2001 From: HcGys <370379459@qq.com> Date: Tue, 4 Jun 2024 22:48:43 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=A1=86=E6=B8=90?= =?UTF-8?q?=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/view/components/TkComment.vue | 4 ++-- src/client/view/components/TkSubmit.vue | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/client/view/components/TkComment.vue b/src/client/view/components/TkComment.vue index 163b0fb2a..f35095bb5 100644 --- a/src/client/view/components/TkComment.vue +++ b/src/client/view/components/TkComment.vue @@ -208,7 +208,7 @@ export default { scrollToComment () { if (window.location.hash.indexOf(this.comment.id) !== -1) { this.$refs['tk-comment'].scrollIntoView({ - behavier: 'smooth' + behavior: 'smooth' }) this.$emit('expand') } @@ -247,7 +247,7 @@ export default { onLoad () { if (this.comment.replies.length > 0) { this.$refs['tk-replies'].lastElementChild.scrollIntoView({ - behavier: 'smooth', + behavior: 'smooth', block: 'center' }) } diff --git a/src/client/view/components/TkSubmit.vue b/src/client/view/components/TkSubmit.vue index 9c45f7820..f6220ceb5 100644 --- a/src/client/view/components/TkSubmit.vue +++ b/src/client/view/components/TkSubmit.vue @@ -1,5 +1,5 @@