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

@ -101,6 +101,8 @@ params:
mapping: mapping:
lightTheme: lightTheme:
darkTheme: darkTheme:
reactionsEnabled: 1
emitMetadata: 0
widgets: widgets:
enabled: enabled:
@ -152,8 +154,8 @@ menu:
weight: -100 weight: -100
pre: home pre: home
params: params:
### For demonstration purpose, the home link will be open in a new tab ### For demonstration purpose, the home link will be open in a new tab
newTab: true newTab: true
related: related:
includeNewer: true includeNewer: true

View File

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