knitr::opts_chunk$set(echo = TRUE)
refinery::renv_load(paste(params$date, params$slug, sep = "_"))
# Enable copy-paste of code chunks
# xaringanExtra::use_clipboard()
htmltools::tagList(
  xaringanExtra::use_clipboard(
    button_text = "<i class=\"fa fa-clipboard fa-2x\"></i>",
    success_text = "<i class=\"fa fa-check fa-2x\" style=\"color: #90BE6D\"></i>",
    error_text = "<i class=\"fa fa-times-circle fa-2x\" style=\"color: #F94144\"></i>"
  ),
  rmarkdown::html_dependency_font_awesome()
)

Note: This post was originally written by Joel Nitta and copied here on November 29, 2021 - see the original post here for a potentially updated version.

TL;DR

#| echo = FALSE,
#| fig.cap = "Image by [Adam Solomon](https://unsplash.com/@solomac) on [unsplash](https://unsplash.com/photos/WHUDOzd5IYU)." 

knitr::include_graphics("img/adam-solomon-WHUDOzd5IYU-unsplash.jpg")

Like many R-bloggers these days, I have made some changes: I switched from blogdown to Distill ^[blogdown and Distill are R packages for making websites. In a nutshell, Distill is much simpler to use than blogdown, at the cost of some design flexibility. For more about making the switch, you can get caught up with posts from Thomas Mock, Frie Preu, Lisa Lendway, and Andreas Handel.], and from disqus to utterances ^[disqus and utterances are tools that let users comment on blog posts. Recently many R-bloggers have been moving away from disqus because it has a habit of tracking user's data and causing page bloat. More recently, when I checked on my disqus account (in the process of migrating away!), it had a option to "opt-out" of data tracking, but that means data-tracking is on by default.]. Several things about utterances appealed to me: free, open-source, no data tracking. But when I started using it, I immediately was turned off by the dual use of GitHub issues as a way to store comments. It just felt odd to have an issue that wasn't an issue!

Fortunately, I'm not the only one to feel this way, and @laymonage actually did something about it: there is now a very similar app to utterances, called giscus. It offers almost the same functionality, but it uses GitHub Discussions as the place to store comments instead of Issues. This makes much more sense to me.

There are several blogposts ^[For example, Vebash Naidoo's tutorial and Michael McCarthy's post describing how to control the location of the comments section.] on how to enable utterances on Distill, but none that I've found so far on giscus. So, here goes!

  1. Enable Discussions on your blog repo. Optionally, if you want to use a non-default Discussions category for storing giscus content, add a new category. I did this and called it "Comments". As recommended by giscus, it's a good idea to set the discussion format to "Announcement" so that non-authorized users can't add content via the Discussions interface (only the giscus widget on your blog).

  2. Install the giscus GitHub app and configure it to have access to your blog's repo.

  3. Go to the giscus app interface, scroll down to "configuration" and fill in the details for your blog. Once you've done so, further down you should see an HTML code block under "Enable giscus" populated with your information.

#| echo = FALSE,
#| fig.cap = "[giscus](https://giscus.app/) configuration menu." 
knitr::include_graphics("img/giscus-config.png")
#| echo = FALSE,
#| fig.cap = "[giscus](https://giscus.app/) HTML block. Once you fill in the fields in the configuration menu, the parts starting with `[ENTER ...]` will get automatically populated." 
knitr::include_graphics("img/giscus-enable.png")

As described in Miles McBain's blogpost, unfortunately in Distill, you can't just paste the HTML directly into an Rmd file. It won't show up. But the same work-around that he describes for utterances also happily works for giscus! Read on...

  1. Add an .html file (I've called mine giscus.html) to the root of your blog repo that looks like this (and is based off of Miles' HTML):

```{html, eval = FALSE}

If you compare the above code with the HTML block in the giscus app (Fig. \@ref(fig:giscus-html)), you should be able to see how the `script.setAttribute` lines above map to the key-value pairs in the HTML block in the giscus app. All we have to do is copy the contents of the HTML block over to this `giscus.html` file. You can [see what my `giscus.html` file looks like here](https://github.com/joelnitta/joelnitta-home/blob/047152c2d1c6cfdeee438b6e23453d4330ece6ef/giscus.html).

6. [Modify `_site.yml`](https://rstudio.github.io/distill/website.html#site-output) so that the `giscus.html` file gets loaded on every Distill article page
^[The `_site.yml` file is longer than this, but I'm just showing the relevant code to add. You can [see my `_site.yml` file here](https://github.com/joelnitta/joelnitta-home/blob/047152c2d1c6cfdeee438b6e23453d4330ece6ef/_site.yml).
]:

output: distill::distill_article: includes: in_header: giscus.html ```

That's it! Or it should be anyways. I recommend trying a test comment to make sure everything is working (nobody will tell you otherwise...)



jhelvy/distillery documentation built on Feb. 22, 2023, 2:11 p.m.