<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mario</title>
    <description>The latest articles on DEV Community by Mario (@estebankt123).</description>
    <link>https://dev.to/estebankt123</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1812397%2F1f112d15-abd9-45f6-8d1b-6cbb5713e14f.jpg</url>
      <title>DEV Community: Mario</title>
      <link>https://dev.to/estebankt123</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/estebankt123"/>
    <language>en</language>
    <item>
      <title>Adding Giscus Comments to Next.js Blog Pages</title>
      <dc:creator>Mario</dc:creator>
      <pubDate>Fri, 06 Mar 2026 04:47:43 +0000</pubDate>
      <link>https://dev.to/estebankt123/adding-giscus-comments-to-nextjs-blog-pages-5e1b</link>
      <guid>https://dev.to/estebankt123/adding-giscus-comments-to-nextjs-blog-pages-5e1b</guid>
      <description>&lt;h2&gt;
  
  
  Why Giscus?
&lt;/h2&gt;

&lt;p&gt;Every blog needs a way to hear from readers. I wanted a comment system that was:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Free and open source — no vendor lock-in or monthly fees&lt;/li&gt;
&lt;li&gt;GitHub-native — my readers are mostly developers already on GitHub&lt;/li&gt;
&lt;li&gt;Zero database — discussions live in a GitHub repo, not a server I manage&lt;/li&gt;
&lt;li&gt;Theme-aware — it had to match my site's light and dark mode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Giscus checks every box. It uses GitHub Discussions as the backend and renders a clean embed on your page. Each URL path gets its own discussion thread automatically.&lt;/p&gt;

&lt;p&gt;Some other options were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://utteranc.es/" rel="noopener noreferrer"&gt;&lt;strong&gt;utterances&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;: **The primary inspiration for giscus. It uses **GitHub Issues i&lt;/strong&gt;nstead of Discussions to store comments. It is extremely lightweight but does not support threaded replies as natively as giscus.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gitalk.github.io/" rel="noopener noreferrer"&gt;&lt;strong&gt;Gitalk&lt;/strong&gt;&lt;/a&gt;**: **A modern component also based on GitHub Issues. It features a "distraction-free" mode and support for multiple languages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vssue:&lt;/strong&gt; Supports not just GitHub, but also GitLab, Bitbucket, Gitee, and Gitea. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;andrewdoering.org +4&lt;/p&gt;

&lt;p&gt;At the end &lt;strong&gt;Giscus&lt;/strong&gt; seemed like the better option.&lt;/p&gt;

&lt;p&gt;Prerequisites&lt;/p&gt;

&lt;p&gt;Before starting, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Next.js project (App Router)&lt;/li&gt;
&lt;li&gt;A GitHub account&lt;/li&gt;
&lt;li&gt;Node.js and npm/yarn/pnpm installed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Create a Dedicated GitHub Repository
&lt;/h2&gt;

&lt;p&gt;Giscus needs a GitHub repo where discussions will be stored. I recommend creating a separate repo (e.g., your-username/blog-comments) rather than&lt;br&gt;
  using your main portfolio repo. This keeps your commit history clean and lets you manage comment permissions independently.&lt;/p&gt;

&lt;p&gt;Go to GitHub → New repository → name it blog-comments → set it to Public (Giscus requires public repos).&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Enable GitHub Discussions
&lt;/h2&gt;

&lt;p&gt;In your new repo:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to Settings → General&lt;/li&gt;
&lt;li&gt;Scroll to the Features section&lt;/li&gt;
&lt;li&gt;Check Discussions&lt;/li&gt;
&lt;li&gt;Click Save&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then navigate to the Discussions tab and create a new category called Blog Comments (type: Announcement works well — it prevents random discussion&lt;br&gt;
   creation).&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Configure Giscus and Get Your IDs
&lt;/h2&gt;

&lt;p&gt;Visit giscus.app and fill in the configuration form:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repository: your-username/blog-comments&lt;/li&gt;
&lt;li&gt;Page ↔ Discussions Mapping: pathname (each URL gets its own thread)&lt;/li&gt;
&lt;li&gt;Discussion Category: Blog Comments&lt;/li&gt;
&lt;li&gt;Features: Enable reactions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After submitting, Giscus will generate a script tag. Copy the data-repo-id and data-category-id values — you'll need these as environment&lt;br&gt;
  variables.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Install the Package
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;npm install @giscus/react&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 5: Create the BlogComments Component
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;app/blog/components/blog-comments.tsx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`  "use client";
  import Giscus from "@giscus/react";
  import { useTheme } from "../../components/theme-provider";
export default function BlogComments() {
    const { theme } = useTheme();
return (
      &amp;lt;section className="mt-16 pt-12 border-t border-[var(--color-primary)]/20"&amp;gt;
        &amp;lt;h2 className="text-2xl font-bold text-[var(--color-text)] mb-8"&amp;gt;
          Comments
        &amp;lt;/h2&amp;gt;
        &amp;lt;Giscus
          repo="your-username/blog-comments"
          repoId={process.env.NEXT_PUBLIC_GISCUS_REPO_ID ?? ""}
          category="Blog Comments"
          categoryId={process.env.NEXT_PUBLIC_GISCUS_CATEGORY_ID ?? ""}
          mapping="pathname"
          reactionsEnabled="1"
          emitMetadata="0"
          inputPosition="top"
          theme={theme === "dark" ? "dark" : "light"}
          lang="en"
          loading="lazy"
        /&amp;gt;
      &amp;lt;/section&amp;gt;
    );
  }`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key detail here is &lt;code&gt;theme={theme === "dark" ? "dark" : "light"}&lt;/code&gt;. By reading from &lt;code&gt;useTheme()&lt;/code&gt; — the same context your toggle button uses Giscus instantly switches its own theme whenever the user flips the site theme. No extra event listeners, no flash of the wrong colors.&lt;/p&gt;

&lt;p&gt;The component is marked "use client" because useTheme is a React hook and Giscus itself needs browser APIs. The rest of your blog page can stay a&lt;br&gt;
  server component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Add Environment Variables
&lt;/h2&gt;

&lt;p&gt;Add to your .env.local:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NEXT_PUBLIC_GISCUS_REPO_ID=R_your_repo_id_here&lt;br&gt;
  NEXT_PUBLIC_GISCUS_CATEGORY_ID=DIC_your_category_id_here&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These are prefixed with NEXT_PUBLIC_ so they're available in the client bundle. They're not secret — they're visible in the Giscus-generated script tag anyway — but keeping them in env vars avoids hardcoding and makes deployment config explicit.&lt;/p&gt;

&lt;p&gt;For Vercel, add the same two variables in Project Settings → Environment Variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Integrate into the Blog Post Page
&lt;/h2&gt;

&lt;p&gt;In app/blog/[slug]/page.tsx, import and render BlogComments inside the narrow content container, after the post body:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import BlogComments from "../components/blog-comments";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// inside the JSX:&lt;br&gt;
  &amp;lt;div className="max-w-3xl mx-auto px-6 lg:px-8"&amp;gt;&lt;br&gt;
    &amp;lt;BlogPostContent body={post.body} /&amp;gt;&lt;br&gt;
    &amp;lt;BlogComments /&amp;gt;&lt;br&gt;
  &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Placing it inside the same max-w-3xl container keeps comments aligned with the reading column — it feels like a natural continuation of the&lt;br&gt;
  article rather than a full-width widget bolted on at the bottom.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Result
&lt;/h2&gt;

&lt;p&gt;Readers who are logged into GitHub can comment directly on any post. Each article gets its own GitHub Discussion thread, created automatically on&lt;br&gt;
  the first comment. Reactions work out of the box. And when a visitor switches the site to dark mode, the comment widget instantly matches — no&lt;br&gt;
  lag, no mismatch.&lt;/p&gt;

&lt;p&gt;The entire setup required zero backend work, zero database, and about 30 lines of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Giscus is one of the cleanest integrations I've added to this portfolio. If you're running a developer blog and your audience is on GitHub, it's hard to beat: free, open source, no cookies, no ads, and the comment data lives in a repo you own.&lt;/p&gt;

&lt;p&gt;If you run into any issues setting this up — or just want to test that comments work — drop a message below.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>nextjs</category>
      <category>github</category>
    </item>
  </channel>
</rss>
