Add reactionsEnabled and emitMetadata config for giscuss

+ Format code
This commit is contained in:
Jimmy Cai 2021-08-15 09:59:13 +00:00 committed by GitHub
parent fb2b92dbbf
commit ecefb45ae1
2 changed files with 27 additions and 20 deletions

View File

@ -94,13 +94,15 @@ params:
lang:
giscus:
repo:
repoID:
category:
categoryID:
mapping:
lightTheme:
darkTheme:
repo:
repoID:
category:
categoryID:
mapping:
lightTheme:
darkTheme:
reactionsEnabled: 1
emitMetadata: 0
widgets:
enabled:
@ -152,8 +154,8 @@ menu:
weight: -100
pre: home
params:
### For demonstration purpose, the home link will be open in a new tab
newTab: true
### For demonstration purpose, the home link will be open in a new tab
newTab: true
related:
includeNewer: true

View File

@ -5,40 +5,45 @@
data-repo-id="{{- .repoID -}}"
data-category="{{- .category -}}"
data-category-id="{{- .categoryID -}}"
data-mapping="{{- default "title" .mapping -}}"
data-reactions-enabled="1"
data-emit-metadata="0"
data-theme="{{- default "light" .lightTheme -}}"
data-mapping="{{- default `title` .mapping -}}"
data-reactions-enabled="{{- default 1 .reactionsEnabled -}}"
data-emit-metadata="{{- default 0 .emitMetadata -}}"
data-theme="{{- default `light` .lightTheme -}}"
crossorigin="anonymous"
async
></script>
<script>
function setGiscusTheme(theme) {
let giscus = document.querySelector('iframe.giscus-frame');
if (giscus) {
giscus.contentWindow.postMessage(
{ giscus: { setConfig: { theme: theme } } },
{
giscus: {
setConfig: {
theme: theme
}
}
},
"https://giscus.app"
);
};
};
(function(){
const head = document.getElementsByTagName("html")[0];
addEventListener('message', handler);
addEventListener('message', (e) => {
if (event.origin !== 'https://giscus.app') return;
handler()
});
window.addEventListener('onColorSchemeChange', handler);
function handler() {
if (head.getAttribute("data-scheme") == "light") {
if (document.documentElement.dataset.scheme === "light") {
setGiscusTheme('{{- default "light" .lightTheme -}}');
} else {
setGiscusTheme('{{- default "dark_dimmed" .darkTheme -}}');
};
};
}());
</script>
{{- end -}}