Integrate utterances comments
This commit is contained in:
parent
75176522e3
commit
d315bf57e7
5 changed files with 64 additions and 6 deletions
|
@ -89,9 +89,13 @@ toc: true
|
||||||
|
|
||||||
comments:
|
comments:
|
||||||
active: # The global switch for posts comments, e.g., 'disqus'. Keep it empty means disable
|
active: # The global switch for posts comments, e.g., 'disqus'. Keep it empty means disable
|
||||||
# The comment active options are as follows
|
# The active options are as follows:
|
||||||
disqus:
|
disqus:
|
||||||
shortname: # fill with the Disqus shortname. › https://help.disqus.com/en/articles/1717111-what-s-a-shortname
|
shortname: # fill with the Disqus shortname. › https://help.disqus.com/en/articles/1717111-what-s-a-shortname
|
||||||
|
# utterances settings › https://utteranc.es/
|
||||||
|
utterances:
|
||||||
|
repo: # <gh-username>/<repo>
|
||||||
|
issue_term: # < url | pathname | title | ...>
|
||||||
|
|
||||||
paginate: 10
|
paginate: 10
|
||||||
|
|
||||||
|
@ -113,7 +117,6 @@ collections:
|
||||||
output: true
|
output: true
|
||||||
sort_by: order
|
sort_by: order
|
||||||
|
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
-
|
-
|
||||||
scope:
|
scope:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<!-- The comments switcher -->
|
<!-- The comments switcher -->
|
||||||
{% if page.comments and site.comments.active %}
|
{% if page.comments and site.comments.active %}
|
||||||
{% include {{ site.comments.active | append: '.html' }} %}
|
{% capture path %}comments/{{ site.comments.active }}.html{% endcapture %}
|
||||||
|
{% include {{ path }} %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
51
_includes/comments/utterances.html
Normal file
51
_includes/comments/utterances.html
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<!-- https://utteranc.es/ -->
|
||||||
|
<script src="https://utteranc.es/client.js"
|
||||||
|
repo="{{ site.comments.utterances.repo }}"
|
||||||
|
issue-term="{{ site.comments.utterances.issue_term }}"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
async>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function() {
|
||||||
|
const origin = "https://utteranc.es";
|
||||||
|
const iframe = "iframe.utterances-frame";
|
||||||
|
const lightTheme = "github-light";
|
||||||
|
const darkTheme = "github-dark";
|
||||||
|
let initTheme = lightTheme;
|
||||||
|
|
||||||
|
if ($("html[mode=dark]").length > 0
|
||||||
|
|| ($("html[mode]").length == 0
|
||||||
|
&& window.matchMedia("(prefers-color-scheme: dark)").matches)) {
|
||||||
|
initTheme = darkTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
addEventListener("message", (event) => {
|
||||||
|
let theme;
|
||||||
|
|
||||||
|
/* credit to <https://github.com/utterance/utterances/issues/170#issuecomment-594036347> */
|
||||||
|
if (event.origin === origin) {
|
||||||
|
/* page initial */
|
||||||
|
theme = initTheme;
|
||||||
|
|
||||||
|
} else if (event.source === window && event.data &&
|
||||||
|
event.data.direction === ModeToggle.ID) {
|
||||||
|
/* global theme mode changed */
|
||||||
|
const mode = event.data.message;
|
||||||
|
theme = (mode === ModeToggle.DARK_MODE ? darkTheme : lightTheme);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = {
|
||||||
|
type: "set-theme",
|
||||||
|
theme: theme
|
||||||
|
};
|
||||||
|
|
||||||
|
const utterances = document.querySelector(iframe).contentWindow;
|
||||||
|
utterances.postMessage(message, origin);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -233,9 +233,12 @@ nav[data-toggle=toc] {
|
||||||
#tail-wrapper {
|
#tail-wrapper {
|
||||||
min-height: 2rem;
|
min-height: 2rem;
|
||||||
|
|
||||||
|
> div:last-of-type {
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
#disqus_thread {
|
#disqus_thread {
|
||||||
min-height: 7.5rem;
|
min-height: 7.5rem;
|
||||||
margin-bottom: 2rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue