Implemented Commento embedding

This commit is contained in:
NaNkeen 2019-05-29 12:11:59 +08:00
parent 3551425f3f
commit b7be3ba672
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,25 @@
<div id="commento"></div>
<script type="text/javascript">
/*
Check and don't inject Commento on localhost/127.0.0.1, however, it does not
work for customised local domains, e.g. example.test, example.dev
*/
(function () {
if (location.hostname === "localhost" ||
location.hostname === "127.0.0.1" ||
location.hostname === "") {
return;
}
var cmt = document.createElement('script');
cmt.type = 'text/javascript';
cmt.async = true;
var commento_host = '{{ with .Site.Params.CommentoHost }}{{ . }}{{else}}https://cdn.commento.io{{ end }}';
cmt.src = commento_host + '/js/commento.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(cmt);
})();
</script>
<noscript>
Please enable JavaScript to view the comments powered by Commento.
</noscript>

View file

@ -5,5 +5,7 @@
{{ partial "page-single/comment/graphcomment.html" . }} {{ partial "page-single/comment/graphcomment.html" . }}
{{ else if .Site.Params.UtterancesRepo }} {{ else if .Site.Params.UtterancesRepo }}
{{ partial "page-single/comment/utterances.html" . }} {{ partial "page-single/comment/utterances.html" . }}
{{ else if .Site.Params.Commento }}
{{ partial "page-single/comment/commento.html" . }}
{{ end }} {{ end }}
{{ end }} {{ end }}