Skip to content

Commit b75c2f6

Browse files
authored
fix(blog): render share and author card before giscus comments
1 parent 1fd0b8c commit b75c2f6

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/components/giscus.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,24 @@
7070
// export default GiscusComments;
7171

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

75-
const GiscusComments: React.FC = () => {
76+
type GiscusCommentsProps = {
77+
forceRender?: boolean;
78+
};
79+
80+
const GiscusComments: React.FC<GiscusCommentsProps> = ({
81+
forceRender = false,
82+
}) => {
7683
const ref = useRef<HTMLDivElement>(null);
84+
const { pathname } = useLocation();
7785
const { colorMode } = useColorMode(); // colorMode is 'light' or 'dark'
86+
const isBlogPostPage = pathname.startsWith("/blog/");
87+
88+
if (isBlogPostPage && !forceRender) {
89+
return null;
90+
}
7891

7992
// 1. This useEffect handles the initial script loading ONCE.
8093
useEffect(() => {

src/theme/BlogPostItem/Footer/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useBlogPost } from "@docusaurus/plugin-content-blog/client";
55
import BlogPostItemFooterOriginal from "@theme-original/BlogPostItem/Footer";
66
import type BlogPostItemFooterType from "@theme/BlogPostItem/Footer";
77
import type { WrapperProps } from "@docusaurus/types";
8+
import GiscusComments from "../../../components/giscus";
89
import SocialShare from "../../../components/SocialShare";
910
import { getAuthorProfile } from "../../../utils/authors";
1011

@@ -149,6 +150,7 @@ export default function BlogPostItemFooterWrapper(props: Props): JSX.Element {
149150
</div>
150151
</section>
151152
)}
153+
{isBlogPostPage && <GiscusComments forceRender />}
152154
</>
153155
);
154156
}

0 commit comments

Comments
 (0)