From 27c6746691721077f4b207d59ced52825805d25d Mon Sep 17 00:00:00 2001 From: radishzzz Date: Fri, 30 May 2025 14:34:24 +0100 Subject: [PATCH] test: add giscus comment --- public/vendors/giscus/theme.css | 99 +++++++++++++++++ src/components/Comments/Giscus.astro | 160 +++++++++++++-------------- src/components/Comments/Waline.astro | 15 ++- src/components/Comments/index.astro | 8 +- src/config.ts | 2 +- src/i18n/config.ts | 2 +- 6 files changed, 194 insertions(+), 92 deletions(-) create mode 100644 public/vendors/giscus/theme.css diff --git a/public/vendors/giscus/theme.css b/public/vendors/giscus/theme.css new file mode 100644 index 0000000..7bf1850 --- /dev/null +++ b/public/vendors/giscus/theme.css @@ -0,0 +1,99 @@ +/*! MIT License + * Copyright (c) 2018 GitHub Inc. + * https://github.com/primer/primitives/blob/main/LICENSE + */ + + main { + --color-prettylights-syntax-comment: #6e7781; + --color-prettylights-syntax-constant: #0550ae; + --color-prettylights-syntax-entity: #8250df; + --color-prettylights-syntax-storage-modifier-import: #24292f; + --color-prettylights-syntax-entity-tag: #116329; + --color-prettylights-syntax-keyword: #cf222e; + --color-prettylights-syntax-string: #0a3069; + --color-prettylights-syntax-variable: #953800; + --color-prettylights-syntax-brackethighlighter-unmatched: #82071e; + --color-prettylights-syntax-invalid-illegal-text: #f6f8fa; + --color-prettylights-syntax-invalid-illegal-bg: #82071e; + --color-prettylights-syntax-carriage-return-text: #f6f8fa; + --color-prettylights-syntax-carriage-return-bg: #cf222e; + --color-prettylights-syntax-string-regexp: #116329; + --color-prettylights-syntax-markup-list: #3b2300; + --color-prettylights-syntax-markup-heading: #0550ae; + --color-prettylights-syntax-markup-italic: #24292f; + --color-prettylights-syntax-markup-bold: #24292f; + --color-prettylights-syntax-markup-deleted-text: #82071e; + --color-prettylights-syntax-markup-deleted-bg: #ffebe9; + --color-prettylights-syntax-markup-inserted-text: #116329; + --color-prettylights-syntax-markup-inserted-bg: #dafbe1; + --color-prettylights-syntax-markup-changed-text: #953800; + --color-prettylights-syntax-markup-changed-bg: #ffd8b5; + --color-prettylights-syntax-markup-ignored-text: #eaeef2; + --color-prettylights-syntax-markup-ignored-bg: #0550ae; + --color-prettylights-syntax-meta-diff-range: #8250df; + --color-prettylights-syntax-brackethighlighter-angle: #57606a; + --color-prettylights-syntax-sublimelinter-gutter-mark: #8c959f; + --color-prettylights-syntax-constant-other-reference-link: #0a3069; + --color-btn-text: #24292f; + --color-btn-bg: #f6f8fa; + --color-btn-border: rgb(31 35 40 / 15%); + --color-btn-shadow: 0 1px 0 rgb(31 35 40 / 4%); + --color-btn-inset-shadow: inset 0 1px 0 rgb(255 255 255 / 25%); + --color-btn-hover-bg: #f3f4f6; + --color-btn-hover-border: rgb(31 35 40 / 15%); + --color-btn-active-bg: hsl(220deg 14% 93% / 100%); + --color-btn-active-border: rgb(31 35 40 / 15%); + --color-btn-selected-bg: hsl(220deg 14% 94% / 100%); + --color-btn-primary-text: #fff; + --color-btn-primary-bg: #1f883d; + --color-btn-primary-border: rgb(31 35 40 / 15%); + --color-btn-primary-shadow: 0 1px 0 rgb(31 35 40 / 10%); + --color-btn-primary-inset-shadow: inset 0 1px 0 rgb(255 255 255 / 3%); + --color-btn-primary-hover-bg: #1a7f37; + --color-btn-primary-hover-border: rgb(31 35 40 / 15%); + --color-btn-primary-selected-bg: hsl(137deg 66% 28% / 100%); + --color-btn-primary-selected-shadow: inset 0 1px 0 rgb(0 45 17 / 20%); + --color-btn-primary-disabled-text: rgb(255 255 255 / 80%); + --color-btn-primary-disabled-bg: #94d3a2; + --color-btn-primary-disabled-border: rgb(31 35 40 / 15%); + --color-action-list-item-default-hover-bg: rgb(208 215 222 / 32%); + --color-segmented-control-bg: #eaeef2; + --color-segmented-control-button-bg: #fff; + --color-segmented-control-button-selected-border: #8c959f; + --color-fg-default: #1F2328; + --color-fg-muted: #656d76; + --color-fg-subtle: #6e7781; + --color-canvas-default: #fff; + --color-canvas-overlay: #fff; + --color-canvas-inset: #f6f8fa; + --color-canvas-subtle: #f6f8fa; + --color-border-default: #d0d7de; + --color-border-muted: hsl(210deg 18% 87% / 100%); + --color-neutral-muted: rgb(175 184 193 / 20%); + --color-accent-fg: #0969da; + --color-accent-emphasis: #0969da; + --color-accent-muted: rgb(84 174 255 / 40%); + --color-accent-subtle: #ddf4ff; + --color-success-fg: #1a7f37; + --color-attention-fg: #9a6700; + --color-attention-muted: rgb(212 167 44 / 40%); + --color-attention-subtle: #fff8c5; + --color-danger-fg: #d1242f; + --color-danger-muted: rgb(255 129 130 / 40%); + --color-danger-subtle: #ffebe9; + --color-primer-shadow-inset: inset 0 1px 0 rgb(208 215 222 / 20%); + --color-scale-gray-1: #eaeef2; + --color-scale-blue-1: #b6e3ff; + + /*! Extensions from @primer/css/alerts/flash.scss */ + --color-social-reaction-bg-hover: var(--color-scale-gray-1); + --color-social-reaction-bg-reacted-hover: var(--color-scale-blue-1); +} + +main .pagination-loader-container { + background-image: url("https://github.com/images/modules/pulls/progressive-disclosure-line.svg"); +} + +main .gsc-loading-image { + background-image: url("https://github.githubassets.com/images/mona-loading-default.gif"); +} \ No newline at end of file diff --git a/src/components/Comments/Giscus.astro b/src/components/Comments/Giscus.astro index ed3b9cf..b217ff2 100644 --- a/src/components/Comments/Giscus.astro +++ b/src/components/Comments/Giscus.astro @@ -2,93 +2,89 @@ import { defaultLocale, themeConfig } from '@/config' import { giscusLocaleMap } from '@/i18n/config' -// Get the language code of Giscus -function getGiscusLang(currentPath: string, defaultLocale: string): string { - // Extract language code from path - const pathLang = Object.keys(giscusLocaleMap).find(code => - currentPath.startsWith(`/${code}/`), - ) - // Return found path language or default language - const lang = pathLang || defaultLocale - return giscusLocaleMap[lang as keyof typeof giscusLocaleMap] -} - -const giscusLang = getGiscusLang(Astro.url.pathname, defaultLocale) const { - repo = "", - repoID = "", - category = "", - categoryID = "", - mapping = "pathname", - inputPosition = "top", - loading = "lazy", -} = themeConfig.comment?.giscus ?? {}; + repo = '', + repoID = '', + category = '', + categoryID = '', + mapping = 'pathname', + strict = '0', + reactionsEnabled = '1', + emitMetadata = '0', + inputPosition = 'bottom', +} = themeConfig.comment?.giscus ?? {} + +const siteUrl = themeConfig.site.url +const shouldRender = Boolean(repo && repoID && categoryID) --- -
+{shouldRender && ( +
- + setupGiscus() + document.addEventListener('astro:page-load', setupGiscus) + +)} diff --git a/src/components/Comments/Waline.astro b/src/components/Comments/Waline.astro index 643914c..e204cf0 100644 --- a/src/components/Comments/Waline.astro +++ b/src/components/Comments/Waline.astro @@ -2,7 +2,14 @@ import { defaultLocale, themeConfig } from '@/config' import { walineLocaleMap } from '@/i18n/config' -const { waline: { serverURL = '', emoji = [], search = false, imageUploader = false } = {} } = themeConfig.comment ?? {} +const { + waline: { + serverURL = '', + emoji = [], + search = false, + imageUploader = false, + } = {}, +} = themeConfig.comment ?? {} ---
import { init } from '/vendors/waline/waline.js' -function initWaline() { +function setupWaline() { const currentPath = window.location.pathname const pathLang = Object.keys(walineLocaleMap).find(code => currentPath.startsWith(`/${code}/`), @@ -50,8 +57,8 @@ function initWaline() { }) } -initWaline() -document.addEventListener('astro:page-load', initWaline) +setupWaline() +document.addEventListener('astro:page-load', setupWaline) diff --git a/src/components/Comments/index.astro b/src/components/Comments/index.astro index 7357df6..f36d303 100644 --- a/src/components/Comments/index.astro +++ b/src/components/Comments/index.astro @@ -1,6 +1,6 @@ --- // import Disqus from '@/components/Comments/Disqus.astro' -// import Giscus from '@/components/Comments/Giscus.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' @@ -12,8 +12,8 @@ const enableComments = themeConfig.comment?.enabled ?? false // const showDisqus = enableComments && disqusShortname.trim() !== '' // Giscus -// const giscusRepo = themeConfig.comment?.giscus?.repo || '' -// const showGiscus = enableComments && giscusRepo.trim() !== '' +const giscusRepo = themeConfig.comment?.giscus?.repo || '' +const showGiscus = enableComments && giscusRepo.trim() !== '' // Twikoo // const twikooEnvId = themeConfig.comment?.twikoo?.envId || '' @@ -25,6 +25,6 @@ const showWaline = enableComments && walineURL.trim() !== '' --- - +{showGiscus && } {showWaline && } diff --git a/src/config.ts b/src/config.ts index 39b230c..2f89a34 100644 --- a/src/config.ts +++ b/src/config.ts @@ -75,7 +75,7 @@ export const themeConfig: ThemeConfig = { // https://waline.js.org/en/ waline: { // server url - serverURL: 'https://retypeset-comment.radishzz.cc', + serverURL: '', // emoji url emoji: [ 'https://unpkg.com/@waline/emojis@1.2.0/tw-emoji', diff --git a/src/i18n/config.ts b/src/i18n/config.ts index 959b21f..553d7b8 100644 --- a/src/i18n/config.ts +++ b/src/i18n/config.ts @@ -36,7 +36,7 @@ export const giscusLocaleMap: Record = { 'en': 'en', 'es': 'es', 'fr': 'fr', - 'ja': 'jp', + 'ja': 'ja', 'ko': 'ko', 'pl': 'pl', 'pt': 'pt',