Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/giscus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,24 @@
// export default GiscusComments;

import React, { useEffect, useRef } from "react";
import { useLocation } from "@docusaurus/router";
import { useColorMode } from "@docusaurus/theme-common";

const GiscusComments: React.FC = () => {
type GiscusCommentsProps = {
forceRender?: boolean;
};

const GiscusComments: React.FC<GiscusCommentsProps> = ({
forceRender = false,
}) => {
const ref = useRef<HTMLDivElement>(null);
const { pathname } = useLocation();
const { colorMode } = useColorMode(); // colorMode is 'light' or 'dark'
const isBlogPostPage = pathname.startsWith("/blog/");

if (isBlogPostPage && !forceRender) {
return null;
}

// 1. This useEffect handles the initial script loading ONCE.
useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/theme/BlogPostItem/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useBlogPost } from "@docusaurus/plugin-content-blog/client";
import BlogPostItemFooterOriginal from "@theme-original/BlogPostItem/Footer";
import type BlogPostItemFooterType from "@theme/BlogPostItem/Footer";
import type { WrapperProps } from "@docusaurus/types";
import GiscusComments from "../../../components/giscus";
import SocialShare from "../../../components/SocialShare";
import { getAuthorProfile } from "../../../utils/authors";

Expand Down Expand Up @@ -149,6 +150,7 @@ export default function BlogPostItemFooterWrapper(props: Props): JSX.Element {
</div>
</section>
)}
{isBlogPostPage && <GiscusComments forceRender />}
</>
);
}
Loading