mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-15 11:12:54 +02:00
test: add giscus comment
This commit is contained in:
parent
d12e235a23
commit
27c6746691
6 changed files with 194 additions and 92 deletions
99
public/vendors/giscus/theme.css
vendored
Normal file
99
public/vendors/giscus/theme.css
vendored
Normal file
|
@ -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");
|
||||
}
|
|
@ -2,30 +2,27 @@
|
|||
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)
|
||||
---
|
||||
|
||||
<div class="giscus mt-16" id="giscus-container"></div>
|
||||
{shouldRender && (
|
||||
<div
|
||||
id="giscus"
|
||||
class="giscus mt-16"
|
||||
></div>
|
||||
|
||||
<script
|
||||
is:inline
|
||||
|
@ -35,60 +32,59 @@ const {
|
|||
category,
|
||||
categoryID,
|
||||
mapping,
|
||||
strict,
|
||||
reactionsEnabled,
|
||||
emitMetadata,
|
||||
inputPosition,
|
||||
giscusLang,
|
||||
loading,
|
||||
giscusLocaleMap,
|
||||
defaultLocale,
|
||||
siteUrl,
|
||||
}}
|
||||
>
|
||||
const host = window.location.origin;
|
||||
function setupGiscus() {
|
||||
const giscusContainer = document.getElementById('giscus')
|
||||
if (!giscusContainer)
|
||||
return
|
||||
|
||||
function loadGiscus() {
|
||||
const existingScript = document.querySelector("script[src*='giscus.app']");
|
||||
if (existingScript) {
|
||||
existingScript.remove();
|
||||
}
|
||||
const giscusContainer = document.getElementById("giscus-container");
|
||||
if (giscusContainer) giscusContainer.innerHTML = "";
|
||||
// 创建新脚本
|
||||
const theme = document.documentElement.classList.contains("dark")
|
||||
? host + "/css/giscus_dark.css"
|
||||
: host + "/css/giscus_light.css";
|
||||
const script = document.createElement("script");
|
||||
script.src = "https://giscus.app/client.js";
|
||||
script.setAttribute("data-repo", repo);
|
||||
script.setAttribute("data-repo-id", repoID);
|
||||
script.setAttribute("data-category", category);
|
||||
script.setAttribute("data-category-id", categoryID);
|
||||
script.setAttribute("data-mapping", mapping);
|
||||
script.setAttribute("data-strict", "0");
|
||||
script.setAttribute("data-reactions-enabled", "1");
|
||||
script.setAttribute("data-theme", theme);
|
||||
script.setAttribute("data-emit-metadata", "0");
|
||||
script.setAttribute("data-input-position", inputPosition);
|
||||
script.setAttribute("data-lang", giscusLang);
|
||||
script.setAttribute("data-loading", loading);
|
||||
script.crossOrigin = "anonymous";
|
||||
script.async = true;
|
||||
giscusContainer.appendChild(script);
|
||||
giscusContainer.innerHTML = ''
|
||||
|
||||
const currentPath = window.location.pathname
|
||||
const pathLang = Object.keys(giscusLocaleMap).find(code =>
|
||||
currentPath.startsWith(`/${code}/`),
|
||||
)
|
||||
const lang = pathLang || defaultLocale
|
||||
const currentGiscusLang = giscusLocaleMap[lang]
|
||||
|
||||
const script = document.createElement('script')
|
||||
script.src = 'https://giscus.app/client.js'
|
||||
script.crossOrigin = 'anonymous'
|
||||
script.async = true
|
||||
|
||||
// Set up basic attributes
|
||||
const dataAttributes = {
|
||||
repo,
|
||||
repoId: repoID,
|
||||
categoryId: categoryID,
|
||||
mapping,
|
||||
strict,
|
||||
reactionsEnabled,
|
||||
emitMetadata,
|
||||
inputPosition,
|
||||
theme: `${siteUrl}/vendors/giscus/theme.css`,
|
||||
lang: currentGiscusLang,
|
||||
}
|
||||
|
||||
function changeGiscusTheme() {
|
||||
const iframe = document.querySelector("iframe.giscus-frame");
|
||||
if (!iframe || iframe.classList.contains("giscus-frame--loading")) {
|
||||
// 脚本未加载场景
|
||||
loadGiscus();
|
||||
return;
|
||||
};
|
||||
const theme = document.documentElement.classList.contains("dark")
|
||||
? host + "/css/giscus_dark.css"
|
||||
: host + "/css/giscus_light.css";
|
||||
iframe.contentWindow.postMessage(
|
||||
{ giscus: { setConfig: { theme } } },
|
||||
"https://giscus.app",
|
||||
);
|
||||
// Add category conditionally
|
||||
if (category)
|
||||
dataAttributes.category = category
|
||||
|
||||
// Apply all attributes
|
||||
Object.assign(script.dataset, dataAttributes)
|
||||
|
||||
giscusContainer.appendChild(script)
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", loadGiscus);
|
||||
document.addEventListener("theme-changed", changeGiscusTheme);
|
||||
document.addEventListener("astro:page-load", loadGiscus);
|
||||
setupGiscus()
|
||||
document.addEventListener('astro:page-load', setupGiscus)
|
||||
</script>
|
||||
)}
|
||||
|
|
|
@ -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 ?? {}
|
||||
---
|
||||
|
||||
<div
|
||||
|
@ -25,7 +32,7 @@ const { waline: { serverURL = '', emoji = [], search = false, imageUploader = fa
|
|||
>
|
||||
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)
|
||||
</script>
|
||||
|
||||
<!-- Custom CSS Styles >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
|
||||
|
|
|
@ -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() !== ''
|
|||
---
|
||||
|
||||
<!-- {showDisqus && <Disqus />} -->
|
||||
<!-- {showGiscus && <Giscus />} -->
|
||||
{showGiscus && <Giscus />}
|
||||
<!-- {showTwikoo && <Twikoo />} -->
|
||||
{showWaline && <Waline />}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -36,7 +36,7 @@ export const giscusLocaleMap: Record<string, string> = {
|
|||
'en': 'en',
|
||||
'es': 'es',
|
||||
'fr': 'fr',
|
||||
'ja': 'jp',
|
||||
'ja': 'ja',
|
||||
'ko': 'ko',
|
||||
'pl': 'pl',
|
||||
'pt': 'pt',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue