From 63894572174bc6673620b16b32f4cbbf64387db4 Mon Sep 17 00:00:00 2001 From: Usman Shahid Date: Sat, 1 Aug 2026 22:54:39 +0400 Subject: [PATCH] feat(blog): add giscus comments + reactions and Cloudflare Web Analytics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comments and upvotes run entirely on GitHub via giscus (GitHub Discussions) — no database, no build dependency, data lives in this repo's Discussions. The component is theme-synced to the site's light/dark toggle, lazy-loaded, and each post can opt out with a 'comments: false' frontmatter flag. Page views use Cloudflare Web Analytics (privacy-first, no cookies); the beacon renders only when a public token is set in src/consts.ts. Co-Authored-By: Claude Opus 4.8 --- src/components/Comments.astro | 104 +++++++++++++++++++++++++++++++++ src/consts.ts | 8 +++ src/content.config.ts | 2 + src/layouts/Base.astro | 14 +++++ src/pages/blog/[...slug].astro | 15 ++++- 5 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 src/components/Comments.astro create mode 100644 src/consts.ts diff --git a/src/components/Comments.astro b/src/components/Comments.astro new file mode 100644 index 0000000..32eabed --- /dev/null +++ b/src/components/Comments.astro @@ -0,0 +1,104 @@ +--- +// Comments + reactions via giscus, backed by GitHub Discussions. No database, +// no build dependency — data lives in this repo's Discussions. +// +// One-time setup (repo owner): install the giscus GitHub App and grant it +// access to this repo -> https://github.com/apps/giscus +// (Discussions is already enabled and the IDs below are this repo's.) +const GISCUS = { + repo: "codemug/codemug.github.io", + repoId: "R_kgDOSqw0-w", + category: "Announcements", + categoryId: "DIC_kwDOSqw0-84DCd5X", +}; +--- + +
+

Comments & reactions

+

+ React or leave a comment below — sign in with GitHub. It all lives in this + site's GitHub Discussions. +

+
+
+ + + + diff --git a/src/consts.ts b/src/consts.ts new file mode 100644 index 0000000..fbf629c --- /dev/null +++ b/src/consts.ts @@ -0,0 +1,8 @@ +// Public site configuration. + +// Cloudflare Web Analytics beacon token. Free, privacy-first, no cookies. +// Get it at: dash.cloudflare.com -> Analytics & Logs -> Web Analytics -> +// "Add a site" (use codemug.github.io), then copy the token out of the JS +// snippet it shows (the value of "token"). It is a PUBLIC token (it appears in +// the page HTML), so committing it is fine. Leave empty to disable analytics. +export const CF_BEACON_TOKEN = "28b4ca2200ce4333938cc73bd96e9af2"; diff --git a/src/content.config.ts b/src/content.config.ts index 007342d..7beea4b 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -22,6 +22,8 @@ const blog = defineCollection({ // Optional per-post social-card image (absolute path from /public, e.g. // "/og/my-post.png"). Falls back to the site default. ogImage: z.string().optional(), + // Show the giscus comments + reactions section. Set false to opt a post out. + comments: z.boolean().default(true), }), }); diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 1e4d503..e397448 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -1,5 +1,6 @@ --- import "../styles/global.css"; +import { CF_BEACON_TOKEN } from "../consts"; interface Props { title: string; @@ -199,6 +200,19 @@ const articleJsonLd = /> ) } + + {/* Cloudflare Web Analytics — privacy-first, no cookies. Renders only when + a beacon token is configured in src/consts.ts. */} + { + CF_BEACON_TOKEN && ( +