Skip to content

Commit

Permalink
feat: add giscus comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CoodingPenguin committed Jan 11, 2025
1 parent 9bca8b3 commit 25143a8
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 2 deletions.
100 changes: 100 additions & 0 deletions public/giscus/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
main {
--primary-default: 20, 222, 155;
--bg-default: 22, 22, 24;
--color-prettylights-syntax-comment: #8b949e;
--color-prettylights-syntax-constant: #79c0ff;
--color-prettylights-syntax-entity: #d2a8ff;
--color-prettylights-syntax-storage-modifier-import: #c9d1d9;
--color-prettylights-syntax-entity-tag: #7ee787;
--color-prettylights-syntax-keyword: #ff7b72;
--color-prettylights-syntax-string: #a5d6ff;
--color-prettylights-syntax-variable: #ffa657;
--color-prettylights-syntax-brackethighlighter-unmatched: #f85149;
--color-prettylights-syntax-invalid-illegal-text: #f0f6fc;
--color-prettylights-syntax-invalid-illegal-bg: #8e1519;
--color-prettylights-syntax-carriage-return-text: #f0f6fc;
--color-prettylights-syntax-carriage-return-bg: #b62324;
--color-prettylights-syntax-string-regexp: #7ee787;
--color-prettylights-syntax-markup-list: #f2cc60;
--color-prettylights-syntax-markup-heading: #1f6feb;
--color-prettylights-syntax-markup-italic: #c9d1d9;
--color-prettylights-syntax-markup-bold: #c9d1d9;
--color-prettylights-syntax-markup-deleted-text: #ffdcd7;
--color-prettylights-syntax-markup-deleted-bg: #67060c;
--color-prettylights-syntax-markup-inserted-text: #aff5b4;
--color-prettylights-syntax-markup-inserted-bg: #033a16;
--color-prettylights-syntax-markup-changed-text: #ffdfb6;
--color-prettylights-syntax-markup-changed-bg: #5a1e02;
--color-prettylights-syntax-markup-ignored-text: #c9d1d9;
--color-prettylights-syntax-markup-ignored-bg: #1158c7;
--color-prettylights-syntax-meta-diff-range: #d2a8ff;
--color-prettylights-syntax-brackethighlighter-angle: #8b949e;
--color-prettylights-syntax-sublimelinter-gutter-mark: #484f58;
--color-prettylights-syntax-constant-other-reference-link: #a5d6ff;
--color-btn-text: rgb(235 235 245 / 86%);
--color-btn-bg: rgba(var(--bg-default), 1);
--color-btn-border: rgba(var(--bg-default), 1);
--color-btn-shadow: 0 1px 0 rgba(var(--bg-default), 1);
--color-btn-inset-shadow: inset 0 1px 0 rgba(var(--bg-default), 1);
--color-btn-hover-bg: rgba(var(--bg-default), 0.5);
--color-btn-hover-border: rgba(var(--bg-default), 0.5);
--color-btn-active-bg: rgba(var(--primary-default), 0.2);
--color-btn-active-border: rgba(var(--primary-default), 1);
--color-btn-selected-bg: rgba(var(--primary-default), 0.15);
--color-btn-primary-text: rgb(255 255 255 / 100%);
--color-btn-primary-bg: rgba(var(--primary-default), 0.45);
--color-btn-primary-border: rgba(var(--primary-default), 0.5);
--color-btn-primary-shadow: 0 1px 0 rgb(27 31 36 / 10%);
--color-btn-primary-inset-shadow: inset 0 1px 0 hsl(0deg 0% 100% / 3%);
--color-btn-primary-hover-bg: rgba(var(--primary-default), 0.53);
--color-btn-primary-hover-border: rgba(var(--primary-default), 0.75);
--color-btn-primary-selected-bg: rgba(var(--primary-default), 0.45);
--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: rgba(var(--primary-default), 0.5);
--color-btn-primary-disabled-border: rgba(var(--primary-default), 0.5);
--color-action-list-item-default-hover-bg: rgb(177 186 196 / 12%);
--color-segmented-control-bg: rgb(110 118 129 / 10%);
--color-segmented-control-button-bg: #0d1117;
--color-segmented-control-button-selected-border: rgba(
var(--bg-default),
0.85
);
--color-fg-default: rgb(235 235 245 / 86%);
--color-fg-muted: rgb(235 235 245 / 60%);
--color-fg-subtle: rgb(235 235 245 / 50%);
--color-canvas-default: rgb(30 30 32 / 100%);
--color-canvas-overlay: rgb(30 30 32 / 100%);
--color-canvas-inset: rgba(var(--bg-default), 0.85);
--color-canvas-subtle: rgba(var(--bg-default), 1);
--color-border-default: rgba(var(--bg-default), 0.85);
--color-border-muted: rgb(175 184 193 / 20%);
--color-neutral-muted: rgb(175 184 193 / 20%);
--color-accent-fg: rgba(var(--primary-default), 0.85);
--color-accent-emphasis: rgba(var(--primary-default), 0.95);
--color-accent-muted: rgba(var(--primary-default), 0.4);
--color-accent-subtle: rgba(var(--primary-default), 0.1);
--color-success-fg: #3fb950;
--color-attention-fg: #d29922;
--color-attention-muted: rgb(187 128 9 / 40%);
--color-attention-subtle: rgb(187 128 9 / 15%);
--color-danger-fg: #f85149;
--color-danger-muted: rgb(248 81 73 / 40%);
--color-danger-subtle: rgb(248 81 73 / 10%);
--color-primer-shadow-inset: 0 1px 0 rgba(var(--bg-default), 1),
inset 0 1px 0 rgba(var(--bg-default), 1);
--color-scale-gray-7: rgb(22 22 24 / 100%);
--color-scale-blue-8: rgb(16 185 129 / 15%);

/*! Extensions from @primer/css/alerts/flash.scss */
--color-social-reaction-bg-hover: var(--color-scale-gray-7);
--color-social-reaction-bg-reacted-hover: var(--color-scale-blue-8);
}

main .pagination-loader-container {
background-image: url("https://github.com/images/modules/pulls/progressive-disclosure-line-dark.svg");
}

main .gsc-loading-image {
background-image: url("https://github.githubassets.com/images/mona-loading-dark.gif");
}
104 changes: 104 additions & 0 deletions public/giscus/light.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
main {
--primary-default: 5, 92, 55;
--bg-default: 246, 246, 247;
--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: rgba(var(--bg-default), 1);
--color-btn-border: rgba(var(--bg-default), 1);
--color-btn-shadow: 0 1px 0 rgba(var(--bg-default), 1);
--color-btn-inset-shadow: inset 0 1px 0 rgba(var(--bg-default), 1);
--color-btn-hover-bg: rgba(var(--bg-default), 0.5);
--color-btn-hover-border: rgba(var(--bg-default), 0.5);
--color-btn-active-bg: rgba(var(--primary-default), 0.2);
--color-btn-active-border: rgba(var(--primary-default), 1);
--color-btn-selected-bg: rgba(var(--primary-default), 0.15);
--color-btn-primary-text: rgb(255 255 255 / 100%);
--color-btn-primary-bg: rgba(var(--primary-default), 1);
--color-btn-primary-border: rgba(var(--primary-default), 1);
--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: rgba(var(--primary-default), 0.9);
--color-btn-primary-hover-border: rgba(var(--primary-default), 0.75);
--color-btn-primary-selected-bg: rgba(var(--primary-default), 1);
--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: rgba(var(--primary-default), 0.5);
--color-btn-primary-disabled-border: rgba(var(--primary-default), 0.5);
--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: rgba(
var(--bg-default),
0.85
);
--color-fg-default: rgb(60 60 67);
--color-fg-muted: rgb(60 60 67 / 75%);
--color-fg-subtle: rgb(60 60 67 / 33%);
--color-canvas-default: rgb(255 255 255);
--color-canvas-overlay: rgb(255 255 255);
--color-canvas-inset: rgba(var(--bg-default), 0.85);
--color-canvas-subtle: rgba(var(--bg-default), 1);
--color-border-default: rgba(var(--bg-default), 0.85);
--color-border-muted: rgb(175 184 193 / 20%);
--color-neutral-muted: rgb(175 184 193 / 20%);
--color-accent-fg: rgba(var(--primary-default), 0.85);
--color-accent-emphasis: rgba(var(--primary-default), 0.95);
--color-accent-muted: rgba(var(--primary-default), 0.4);
--color-accent-subtle: rgba(var(--primary-default), 0.1);
--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: 0 1px 0 rgba(var(--bg-default), 1),
inset 0 1px 0 rgba(var(--bg-default), 1);
--color-scale-gray-1: rgb(234 238 242 / 100%);
--color-scale-blue-1: rgb(16 185 129 / 15%);

/*! 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");
}

.gsc-comment:not(.gsc-reply-box) .gsc-replies {
border-radius: unset;
}
42 changes: 42 additions & 0 deletions src/components/GiscusComments.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<section class="mx-auto mt-12">
<script src="https://giscus.app/client.js"
data-repo="coodingpenguin/devlog-astro"
data-repo-id="R_kgDONo23tQ"
data-category="comments"
data-category-id="DIC_kwDONo23tc4Cl7g8"
data-mapping="pathname"
data-strict="0"
data-reactions-enabled="0"
data-emit-metadata="0"
data-input-position="top"
data-theme="preferred_color_scheme"
data-lang="en"
crossorigin="anonymous"
async>
</script>
</section>

<script is:inline>
function updateGiscusTheme() {
const theme = document.documentElement.classList.contains('dark')
? `${new URL(document.URL).origin}/giscus/dark.css`
: `${new URL(document.URL).origin}/giscus/light.css`
const iframe = document.querySelector('iframe.giscus-frame')
if (!iframe) return
iframe.contentWindow.postMessage(
{
giscus: {
setConfig: { theme },
},
},
'https://giscus.app',
)
}

const observer = new MutationObserver(updateGiscusTheme)
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })

window.onload = () => {
updateGiscusTheme()
}
</script>
6 changes: 4 additions & 2 deletions src/pages/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import FormattedDate from "$components/FormattedDate.astro";
import { getBlogPosts } from "src/utils";
import BlueskyLikes from "$components/bluesky/BlueskyLikes.astro";
import Tag from "$components/Tag.astro";
import GiscusComments from "$components/GiscusComments.astro";
export async function getStaticPaths() {
const posts = await getBlogPosts();
Expand Down Expand Up @@ -56,10 +57,11 @@ if (replacedHero && !images[replacedHero])
<h1 class="mt-4">{post.data.title}</h1>
<Content />

<BlueskyLikes
<!-- <BlueskyLikes
disableLikes={post.data.disableLikes}
disableComments={post.data.disableComments}
/>
/> -->
<GiscusComments/>
</BlogPost>
</main>
<Footer />
Expand Down

0 comments on commit 25143a8

Please sign in to comment.