-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enable comments and reactions on blog posts #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { DiscussionEmbed } from 'disqus-react'; | ||
import BlogPostItem from '@theme-original/BlogPostItem'; | ||
import { useBlogPost } from '@docusaurus/plugin-content-blog/client'; | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
import { useColorMode } from '@docusaurus/theme-common'; | ||
|
||
export default function BlogPostItemWrapper(props) { | ||
const { metadata } = useBlogPost(); | ||
const { frontMatter, permalink, title } = metadata; | ||
const currentUrlOrigin = typeof window !== 'undefined' ? window.location.origin : ''; | ||
const fullPermalink = `${currentUrlOrigin}${permalink}`; | ||
const { comments = true } = frontMatter; | ||
const { siteConfig, i18n } = useDocusaurusContext(); | ||
const shortname = siteConfig.customFields.disqusShortname; | ||
const { colorMode } = useColorMode(); | ||
const [disqusColorMode, setDisqusColorMode] = useState(colorMode); | ||
|
||
useEffect(() => { | ||
// Disqus doesn't auto-update when the site's theme changes, | ||
// so we re-render the DiscussionEmbed to reflect the new theme. | ||
setDisqusColorMode(colorMode); | ||
}, [colorMode]); | ||
|
||
return ( | ||
<> | ||
<BlogPostItem {...props} /> | ||
{comments && ( | ||
<DiscussionEmbed | ||
// This property is not used by `DiscussionEmbed`, but forces React to re-render it upon theme changes | ||
colorMode={disqusColorMode} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. React complains about this property's name:
Let's make it happy by using |
||
shortname={shortname} | ||
config={{ | ||
url: fullPermalink, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I thought |
||
title, | ||
language: i18n.currentLocale, | ||
}} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ export default function CopyrightWrapper(props) { | |
const { siteConfig: { customFields: { | ||
siteLicense, | ||
} } } = useDocusaurusContext(); | ||
|
||
anchalshivank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now there is a trailing whitespace... |
||
return ( | ||
<> | ||
<div>Made with ❤️ on Earth.</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should use
${siteConfig.url}
instead of${currentUrlOrigin}
here (see this).