From 6f34372b10ebf4b8d8b4399d4a58441fc1712f86 Mon Sep 17 00:00:00 2001 From: Benny Guo Date: Wed, 2 Aug 2023 16:45:03 +0800 Subject: [PATCH] feat: add waline comment plugin --- _config.yml | 14 ++- src/components/Comment.vue | 88 ++++++++++++++- src/components/Sidebar/src/RecentComment.vue | 41 ++++--- src/models/ThemeConfig.class.ts | 23 +++- src/utils/comments/waline-api.ts | 108 +++++++++++++++++++ src/views/Home.vue | 4 +- templates/index.html | 4 + 7 files changed, 265 insertions(+), 17 deletions(-) create mode 100644 src/utils/comments/waline-api.ts diff --git a/_config.yml b/_config.yml index 6bdffa7d..298999ff 100644 --- a/_config.yml +++ b/_config.yml @@ -126,7 +126,7 @@ valine: lang: en avatarForce: false meta: ['nick', 'mail'] - requiredFields: [] + requiredFields: ['nick', 'mail'] admin: '' # admin username recentComment: true @@ -139,6 +139,18 @@ twikoo: # region: ap-guangzhou # 环境地域,默认为 ap-shanghai,腾讯云环境填 ap-shanghai 或 ap-guangzhou;Vercel 环境不填 lang: 'en' # 用于手动设定评论区语言,支持的语言列表 https://github.com/imaegoo/twikoo/blob/main/src/client/utils/i18n/index.js +# Waline comment plugin +# see https://waline.js.org/guide/get-started/ +waline: + enable: false + recentComment: true + reaction: false + login: 'disable' + meta: ['nick', 'mail'] + requiredMeta: ['nick', 'mail'] + commentSorting: 'latest' + serverURL: '' # 填写服务端地址 + # Enable Busuanzi statistic plugin # see http://ibruce.info/2015/04/04/busuanzi/ busuanzi: diff --git a/src/components/Comment.vue b/src/components/Comment.vue index 05d92554..b51f345d 100644 --- a/src/components/Comment.vue +++ b/src/components/Comment.vue @@ -6,6 +6,7 @@
+
@@ -17,6 +18,12 @@ import { usePostStore } from '@/stores/post' import { twikooInit } from '@/utils/comments/twikoo-api' import { githubInit } from '@/utils/comments/github-api' import { valineInit } from '@/utils/comments/valine-api' +import { walineInit } from '@/utils/comments/waline-api' + +const languages: Record = { + en: 'en', + cn: 'zh' +} export default defineComponent({ name: 'ObComment', @@ -44,6 +51,7 @@ export default defineComponent({ const postUid = toRefs(props).uid const appStore = useAppStore() const postStore = usePostStore() + let waline: any = undefined const enabledComment = ( postTitle: string, @@ -125,6 +133,25 @@ export default defineComponent({ } else if (appStore.themeConfig.plugins.twikoo.enable) { const { envId, region, lang } = appStore.themeConfig.plugins.twikoo twikooInit({ envId, region, lang, path: window.location.pathname }) + } else if (appStore.themeConfig.plugins.waline.enable) { + const { + serverURL, + login, + reaction, + meta, + requiredMeta, + commentSorting + } = appStore.themeConfig.plugins.waline + + waline = walineInit({ + serverURL, + lang: languages[appStore.locale ?? 'en'], + login, + reaction, + meta, + requiredMeta, + commentSorting + }) } } @@ -139,6 +166,19 @@ export default defineComponent({ } ) + /** Updating comments base on current locale */ + watch( + () => appStore.locale, + (newLocale, oldLocale) => { + console.log(newLocale, oldLocale) + if (waline && newLocale !== undefined && newLocale !== oldLocale) { + waline.update({ + lang: languages[newLocale] + }) + } + } + ) + onMounted(() => { enabledComment(postTitle.value, postBody.value, postUid.value) }) @@ -378,7 +418,7 @@ export default defineComponent({ } .tk-avatar { - border: 2px solid var(--text-accent); + border: none; } .tk-nick { @@ -392,4 +432,50 @@ export default defineComponent({ } } } + +#waline { + --waline-theme-color: var(--text-accent); + --waline-border: var(--background-secondary); + --waline-bgcolor: var(--background-primary); + --waline-bgcolor-light: var(--background-secondary); + --waline-badge-color: var(--text-accent); + --waline-disabled-bgcolor: var(--text-dim); + .wl-editor { + @apply p-2 box-border; + } + + .wl-login-nick, + .wl-nick { + color: var(--text-sub-accent); + } + + .wl-card { + @apply bg-ob-deep-900 p-4 rounded-lg; + } + + .wl-num { + color: var(--text-accent); + } + + .primary.wl-btn { + color: var(--text-bright); + border: none; + background: var(--main-gradient); + transition: var(--trans-ease); + &:hover { + opacity: 0.5; + } + } + + .wl-card .wl-delete, + .wl-card .wl-like, + .wl-card .wl-reply, + .wl-card .wl-edit { + color: var(--text-dim); + } + + .wl-card .wl-quote { + border-inline-start: none; + } +} diff --git a/src/components/Sidebar/src/RecentComment.vue b/src/components/Sidebar/src/RecentComment.vue index 3b396f90..5d77e297 100644 --- a/src/components/Sidebar/src/RecentComment.vue +++ b/src/components/Sidebar/src/RecentComment.vue @@ -4,17 +4,19 @@