-->
use giscus
Nowadays a lot of programmers and geeks write their blogs in markdown
and use github page
as their hosts, today we will talk about how to add comments module to our website build with astro
and hosted by github page
.
before every step, you must already have created a website with github page + astro
public
, you can check it in your repository settings, but if you have already made a website (with your github page), this step must have already be done.discussion
on you github repository, in the settings of your repository, scroll down and in the Feature
box, you will find discussion
checkbox, make sure it’s checked. After that you will find the new tag Discussions
appears in the header of your repository.discussions
setting. Give it a name, in the next step you will need this.giscus
in your repository, you can follow this giscus installation/configuration to do that.giscus
settings, open giscus,1057437122/1057437122.github.io
page <==> discussion mapping
, which is Discussion title contains page URL
Load the comments lazily
in Feature
parttheme
After the steps above, you will get a script like this:
<script
src="https://giscus.app/client.js"
data-repo="1057437122/1057437122.github.io"
data-repo-id="MDEwOlJlcG9zaXRvcnkyMTcwMDE5MDA="
data-category="post comments"
data-category-id="DIC_kwDODO8vrM4Cdg2m"
data-mapping="url"
data-strict="0"
data-reactions-enabled="1"
data-emit-metadata="0"
data-input-position="bottom"
data-theme="transparent_dark"
data-lang="en"
data-loading="lazy"
crossOrigin="anonymous"
async
></script>
And in your website source code, write a components like this( for example ):
const Comments = () => {
return (
<script
src="https://giscus.app/client.js"
data-repo="1057437122/1057437122.github.io"
data-repo-id="MDEwOlJlcG9zaXRvcnkyMTcwMDE5MDA="
data-category="post comments"
data-category-id="DIC_kwDODO8vrM4Cdg2m"
data-mapping="url"
data-strict="0"
data-reactions-enabled="1"
data-emit-metadata="0"
data-input-position="bottom"
data-theme="transparent_dark"
data-lang="en"
data-loading="lazy"
crossOrigin="anonymous"
async
></script>
);
};
export { Comments };
Then you can import and use the component everywhere you want, for me I put it in my BlogPost
component like
<Section>
<PostHeader content={props.frontmatter} author={AppConfig.author} />
<PostContent content={props.frontmatter}>{props.children}</PostContent>
<Comments />
</Section>
That’s It!