From eabd33f3397be5050fc97cbb8fae2acedd82157c Mon Sep 17 00:00:00 2001 From: radishzzz Date: Thu, 6 Mar 2025 23:06:38 +0000 Subject: [PATCH] feat: add comment system --- .vscode/settings.json | 3 +++ src/components/Comments/Waline.astro | 2 +- src/components/Comments/index.astro | 27 +++++++++++++++++++++++++++ src/config.ts | 23 ++++++++++++++++------- src/pages/posts/[slug].astro | 4 ++-- src/utils/ui.ts | 2 +- 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 87004bd..82b27d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -65,9 +65,11 @@ "attributify", "blurhash", "bmoji", + "Disqus", "Etiquetas", "Frontmatter", "Fuwriu", + "Giscus", "GSAP", "gtag", "hètí", @@ -92,6 +94,7 @@ "srcset", "STIX", "titlebar", + "Twikoo", "Umami", "unocss", "unpic", diff --git a/src/components/Comments/Waline.astro b/src/components/Comments/Waline.astro index 1476078..72bb1ff 100644 --- a/src/components/Comments/Waline.astro +++ b/src/components/Comments/Waline.astro @@ -35,7 +35,7 @@ function initWaline() { el: '#waline', path: window.location.pathname.replace(/^\/([a-z]{2}(-[a-z]{2})?)\//, '/'), dark: 'auto', - requiredMeta: ['nick'], + requiredMeta: ['nick', 'mail'], highlighter: false, texRenderer: false, reaction: [], diff --git a/src/components/Comments/index.astro b/src/components/Comments/index.astro index e69de29..ea9e47c 100644 --- a/src/components/Comments/index.astro +++ b/src/components/Comments/index.astro @@ -0,0 +1,27 @@ +--- +// import Disqus from '@/components/Comments/Disqus.astro' +// import Giscus from '@/components/Comments/Giscus.astro' +// import Twikoo from '@/components/Comments/Twikoo.astro' +import Waline from '@/components/Comments/Waline.astro' +import { themeConfig } from '@/config' + +// Disqus +// const disqusShortname = themeConfig.comment?.disqus?.shortname || '' +// const showDisqus = disqusShortname.trim() !== '' + +// Giscus +// const giscusRepo = themeConfig.comment?.giscus?.repo || '' +// const showGiscus = giscusRepo.trim() !== '' + +// Twikoo +// const twikooEnvId = themeConfig.comment?.twikoo?.envId || '' +// const showTwikoo = twikooEnvId.trim() !== '' + +// Waline +const walineURL = themeConfig.comment?.waline?.serverURL || '' +const showWaline = walineURL.trim() !== '' +--- + + + +{showWaline && } diff --git a/src/config.ts b/src/config.ts index a13e099..1b9fa0f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -32,24 +32,33 @@ export const themeConfig: ThemeConfig = { // GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START global: { - locale: 'zh', // support 'zh', 'zh-tw', 'ja', 'en', 'es', 'ru'. Default language setting - moreLocale: ['zh-tw', 'ja', 'en', 'es', 'ru'], // ['zh', 'zh-tw', 'ja', 'en', 'es', 'ru']. Not fill in the default locale code again - fontStyle: 'sans', // sans, serif. Font styles for post content - titleSpace: 3, // 1, 2, 3. Space between title and subtitle + // Default language + locale: 'zh', // support 'zh', 'zh-tw', 'ja', 'en', 'es', 'ru' + // Not fill in the default locale code again + moreLocale: ['zh-tw', 'ja', 'en', 'es', 'ru'], // ['zh', 'zh-tw', 'ja', 'en', 'es', 'ru'] + // Font styles for post content + fontStyle: 'sans', // sans, serif + // Space between title and subtitle + titleSpace: 3, // 1, 2, 3 }, // GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END // COMMENT SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START comment: { waline: { - serverURL: 'https://comment.radishzz.cc', // Waline server URL + // Waline server URL + serverURL: 'https://comment.radishzz.cc', // https://comment.example.com + // Emoji emoji: [ 'https://unpkg.com/@waline/emojis@1.2.0/tw-emoji', // 'https://unpkg.com/@waline/emojis@1.2.0/bmoji', // see more at https://waline.js.org/en/guide/features/emoji.html ], - search: false, // whether to enable GIF search - imageUploader: false, // whether to enable image uploader. BUG: + // Whether to enable GIF search + search: false, // true, false + // Whether to enable image uploader + // BUG:unable to disable image uploader + imageUploader: false, // true, false }, }, // COMMENT SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END diff --git a/src/pages/posts/[slug].astro b/src/pages/posts/[slug].astro index f57ac75..ccf30cd 100644 --- a/src/pages/posts/[slug].astro +++ b/src/pages/posts/[slug].astro @@ -1,5 +1,5 @@ --- -import Waline from '@/components/Comments/Waline.astro' +import Comments from '@/components/Comments/index.astro' import Layout from '@/layouts/Layout.astro' import { checkSlugDuplication } from '@/utils/content' import { generatePostPaths } from '@/utils/i18n' @@ -66,5 +66,5 @@ const { Content, remarkPluginFrontmatter } = await post.render() )} - + diff --git a/src/utils/ui.ts b/src/utils/ui.ts index a7dc90c..6a7f88c 100644 --- a/src/utils/ui.ts +++ b/src/utils/ui.ts @@ -9,7 +9,7 @@ export const langMap: Record = { } // Waline Language Map -// see more at https://waline.js.org/guide/i18n.html +// See more at https://waline.js.org/guide/i18n.html export const walineLocaleMap: Record = { 'zh': 'zh-CN', 'zh-tw': 'zh-TW',