[英]GitHub: How to get `utteranc.es` to work for website discussion
My website https://friendly.github.io/HistDataVis/ wants to use the seemingly light weight and useful discussion feature offered by the https://github.com/utterance app.我的网站https://friendly.github.io/HistDataVis/想使用https应用程序提供的看似轻量级和有用的讨论功能。
I believe I have installed it correctly in my repo, https://github.com/friendly/HistDataVis , but it does not appear on the site when built.我相信我已经在我的仓库 https://github.com/friendly/HistDataVis中正确安装了它,但它在构建时没有出现在网站上。
I'm stumped on how to determine what the problem is, or how to correct it.我不知道如何确定问题是什么,或者如何纠正它。 Can anyone help?任何人都可以帮忙吗?
For reference, here is my setup:作为参考,这是我的设置:
The website is built in R Studio, using distill
in rmarkdown.该网站在 R Studio 中构建,在 rmarkdown 中使用distill
。
I created utterances.html
with the standard JS code recommended.我使用推荐的标准 JS 代码创建了utterances.html
。
<script>
document.addEventListener("DOMContentLoaded", function () {
if (!/posts/.test(location.pathname)) {
return;
}
var script = document.createElement("script");
script.src = "https://utteranc.es/client.js";
script.setAttribute("repo", "friendly/HistDataVis");
script.setAttribute("issue-term", "og:title");
script.setAttribute("crossorigin", "anonymous");
script.setAttribute("label", "comments ??");
/* wait for article to load, append script to article element */
var observer = new MutationObserver(function (mutations, observer) {
var article = document.querySelector("d-article");
if (article) {
observer.disconnect();
/* HACK: article scroll */
article.setAttribute("style", "overflow-y: hidden");
article.appendChild(script);
}
});
observer.observe(document.body, { childList: true });
});
</script>
Rmd
file, I use in_header
to insert this into the generated HTML file:在一个Rmd
文件中,我使用in_header
将其插入到生成的 HTML 文件中: ---
title: "Discussion"
date: "`r Sys.Date()`"
output:
distill::distill_article:
toc: true
includes:
in_header: utterances.html
---
Also used this in my _site.yml
file to apply to all Rmd
files on the site.在我的_site.yml
文件中也使用它来应用于站点上的所有Rmd
文件。
On my GitHub account, I installed utterances under GitHub apps, and gave it repository access to the repo for this site.在我的 GitHub 帐户上,我在 GitHub 应用程序下安装了 utterances,并授予它对该站点存储库的存储库访问权限。
This part of your code:这部分代码:
if (!/posts/.test(location.pathname)) {
return;
}
Prevents the rest of the script to load because it's always true
.阻止脚本的 rest 加载,因为它总是true
。
The condition checks whether the value of location.pathname
passes the regular expression test string posts
and negates it ( !
).条件检查location.pathname
的值是否通过正则表达式测试字符串posts
并否定它 ( !
)。 That means the condition is true
if the location.pathname
(the path name of the current URL, eg /HistDataVis/
for https://friendly.github.io/HistDataVis/
) does not contain posts
anywhere in the string. That means the condition is true
if the location.pathname
(the path name of the current URL, eg /HistDataVis/
for https://friendly.github.io/HistDataVis/
) does not contain posts
anywhere in the string. None of the pages on your website has posts
in the pathname
, so the script will end there.您网站上的所有页面都没有pathname
中的posts
,因此脚本将在那里结束。
It should work if you change /posts/
to /HistDataVis
or just remove the if
block altogether.如果您将/posts/
更改为/HistDataVis
或完全删除if
块,它应该可以工作。
Alternatively, you can also try giscus , a similar project that uses GitHub Discussions instead of Issues.或者,您也可以尝试使用GitHub讨论而不是问题的类似项目 giscus。 Someone already made a guide on how to use it with Distill .有人已经就如何将它与Distill一起使用制作了指南。 Disclaimer: I'm the developer of giscus.免责声明:我是 giscus 的开发者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.