From 76b65556f7c3c1aeee878021854cb204a26b5e39 Mon Sep 17 00:00:00 2001 From: FjellOverflow Date: Sat, 27 Jul 2024 05:01:25 +0200 Subject: [PATCH] docs: add guide on integrating user comments with Giscus (#335) --- .../blog/how-to-integrate-giscus-comments.md | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 src/content/blog/how-to-integrate-giscus-comments.md diff --git a/src/content/blog/how-to-integrate-giscus-comments.md b/src/content/blog/how-to-integrate-giscus-comments.md new file mode 100644 index 000000000..a27496f59 --- /dev/null +++ b/src/content/blog/how-to-integrate-giscus-comments.md @@ -0,0 +1,202 @@ +--- +author: FjellOverflow +pubDatetime: 2024-07-25T11:11:53Z +title: How to integrate Giscus comments into AstroPaper +slug: how-to-integrate-giscus-comments +featured: true +draft: false +tags: + - astro + - blog + - docs +description: Comment function on a static blog hosted on GitHub Pages with Giscus. +--- + +Hosting a thin static blog on a platform like [GitHub Pages](https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site) has numerous advantages, but also takes away some interactivity. Fortunately, [Giscus](https://giscus.app/) exists and offers a way to embed user comments on static sites. + +## Table of contents + +## How _Giscus_ works + +[Giscus uses the GitHub API](https://github.com/giscus/giscus?tab=readme-ov-file#how-it-works) to read and store comments made by _GitHub_ users in the `Discussions` associated with a repository. + +Embed the _Giscus_ client-side script bundle on your site, configure it with the correct repository URL, and users can view and write comments (when logged into _GitHub_). + +The approach is serverless, as the comments are stored on _GitHub_ and dynamically loaded from there on client side, hence perfect for a static blog, like _AstroPaper_. + +## Setting up _Giscus_ + +_Giscus_ can be set up easily on [giscus.app](https://giscus.app/), but I will outline the process shortly still. + +### Prequisites + +Prequisites to get _Giscus_ working are + +- the repository is [public](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/setting-repository-visibility#making-a-repository-public) +- the [Giscus app](https://github.com/apps/giscus) is installed +- the [Discussions](https://docs.github.com/en/github/administering-a-repository/managing-repository-settings/enabling-or-disabling-github-discussions-for-a-repository) feature is turned on for your repository + +If any of these conditions cannot be fulfilled for any reason, unfortunately, _Giscus_ cannot be integrated. + +### Configuring _Giscus_ + +Next, configuring _Giscus_ is necessary. In most cases, the preselected defaults are suitable, and you should only modify them if you have a specific reason and know what you are doing. Don't worry too much about making the wrong choices; you can always adjust the configuration later on. + +However you need to + +- select the right language for the UI +- specify the _GitHub_ repository you want to connect, typically the repository containing your statically hosted _AstroPaper_ blog on _GitHub Pages_ +- create and set an `Announcement` type discussion on _GitHub_ if you want to ensure nobody can create random comments directly on _GitHub_ +- define the color scheme + +After configuring the settings, _Giscus_ provides you with a generated ` +``` + +Simply add that to the source code of the site. Most likely, if you're using _AstroPaper_ and want to enable comments on posts, navigate to `src/layouts/PostDetails.astro` and paste it into the desired location where you want the comments to appear, perhaps underneath the `Share this post on:` buttons. + +```diff + + + ++