Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Giscus comment/like React component for blog #2

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 23 additions & 0 deletions components/giscus-comments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Giscus from "@giscus/react";

export default function Comment() {
return (
<>
<br />
<hr />
<br />
{process.env.NEXT_PUBLIC_REPO && process.env.NEXT_PUBLIC_REPO_ID && process.env.NEXT_PUBLIC_CATEGORY_ID ? (
<Giscus
repo= {process.env.NEXT_PUBLIC_REPO as `${string}/${string}`}
repoId= {process.env.NEXT_PUBLIC_REPO_ID}
category="Announcements"
categoryId= {process.env.NEXT_PUBLIC_CATEGORY_ID}
mapping="pathname"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what determines which discussion the comments are placed in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it creates a thread in the category specified based off of the path like 'blog/hello-world' for example. It might be a good idea to host and pull the comments on a separate repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool, let's experiment with that in our preview environment in https://github.com/WATonomous/infra-config

reactionsEnabled="1"
emitMetadata="0"
theme="dark"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set this dynamically? Example:

theme={darkMode === true ? "dark" : darkMode === false ? "light" : "system"}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any context as to how the darkMode variable is set? I am trying to do this but it seems to always be set as true. Also, would something like a useEffect() be able to update the comments component to change theme even after the page is rendered?

Copy link
Member

@ben-z ben-z May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable should be set according to the setting near the footer on every page:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, even if I load the page with light mode the variable is still showing up as true not sure why

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, perhaps try this approach instead? I do remember one of these approaches didn't work as expected during development, but didn't look too deeply into it.

const { theme } = useTheme();
const uppyTheme = theme === 'dark' ? 'dark' : theme === 'light' ? 'light' : 'auto';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed to work. I'll create a new PR once I have access to the infra-config repo. Thanks for the help!

/>
) : null}
</>
);
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"homepage": "https://github.com/WATonomous/infra-config#readme",
"description": "A website for WATcloud",
"dependencies": {
"@giscus/react": "^3.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there no changes in package-lock.json?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes there was I'll add it

"@hookform/resolvers": "^3.3.3",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-checkbox": "^1.0.4",
Expand All @@ -53,8 +54,8 @@
"cmdk": "^0.2.0",
"core-js": "^3.34.0",
"dayjs": "^1.11.10",
"js-sha256": "^0.11.0",
"js-base64": "^3.7.7",
"js-sha256": "^0.11.0",
"lucide-react": "^0.288.0",
"next": "^13.4.19",
"nextjs-google-analytics": "^2.3.3",
Expand All @@ -64,6 +65,7 @@
"react-dom": "^18.2.0",
"react-hook-form": "^7.49.2",
"sha512crypt-node": "^1.0.2",
"sharp": "^0.33.4",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the sharp library necessary?

Copy link
Member Author

@ayaan-d ayaan-d May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was just needed for me to be able to deploy locally. I'll remove it from the dependencies.

"sonner": "^1.4.41",
"strip-indent": "^4.0.0",
"swr": "^2.2.4",
Expand Down
6 changes: 6 additions & 0 deletions pages/blog/hello-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ date: 2023-11-02
timezone: America/Vancouver
---

import Comment from '@/components/giscus-comments'

# Hello, World!

This is a test blog post to see if the Giscus comments work.

<Comment />

{/* Reference for styling: https://github.com/vercel/turbo/blob/22585c9dcc23eb010ab01f177394358af03210d7/docs/pages/blog/turbo-1-10-0.mdx */}
Loading