hugo-theme-anubis2/layouts/partials/giscus.html

50 lines
2.7 KiB
HTML
Raw Permalink Normal View History

2024-03-18 11:38:18 +01:00
{{ $theme := .Site.Params.GiscusTheme | default "preferred_color_scheme" }} {{ $mapping :=
.Site.Params.GiscusDataMapping | default "og:title" }} {{ $language := .Site.Params.GiscusLang | default "en" }} {{
$category := .Site.Params.GiscusDiscussionCategory | default "Announcements" }} {{ $lazyload
:= .Site.Params.GiscusLazyLoad | default false }} {{ $colorTheme := "auto" }} {{ if and (isset site.Params "colortheme")
(ne site.Params.colortheme "") }} {{ $colorTheme = site.Params.colortheme | lower }} {{ end }}
2023-09-18 06:04:34 +02:00
2024-03-18 09:58:43 +01:00
<script>
2024-03-18 11:38:18 +01:00
function detectCurrentScheme2() {
const defaultTheme = "{{ $colorTheme }}";
if (localStorage !== null && localStorage.getItem("user-color-scheme")) {
return localStorage.getItem("user-color-scheme");
}
if (defaultTheme === "dark" || defaultTheme === "light") {
return defaultTheme;
}
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2024-03-18 09:58:43 +01:00
}
2024-03-18 11:38:18 +01:00
let giscusTheme = detectCurrentScheme2();
2024-03-18 09:58:43 +01:00
let giscusAttributes = {
2024-03-18 11:38:18 +01:00
src: "https://giscus.app/client.js",
2024-03-18 09:58:43 +01:00
"data-repo": "{{- .Site.Params.GiscusRepo -}}",
"data-repo-id": "{{- .Site.Params.GiscusRepoId -}}",
"data-category": "{{- $category -}}",
"data-category-id": "{{- .Site.Params.GiscusCategoryId -}}",
"data-mapping": "{{ $mapping }}",
"data-strict": "0",
"data-reactions-enabled": "1",
"data-emit-metadata": "0",
"data-input-position": "bottom",
"data-theme": giscusTheme,
"data-lang": "{{ $language }}",
2024-03-18 11:38:18 +01:00
crossorigin: "anonymous",
lazyload: "{{ $lazyload }}",
async: true,
};
let main = document.querySelector("main");
let giscusScript = document.createElement("script");
2024-03-18 09:58:43 +01:00
Object.entries(giscusAttributes).forEach(([key, value]) => giscusScript.setAttribute(key, value));
main.appendChild(giscusScript);
</script>
2024-03-18 11:38:18 +01:00
{{/*
<script src="https://giscus.app/client.js" data-repo="{{- .Site.Params.GiscusRepo -}}"
data-repo-id="{{- .Site.Params.GiscusRepoId -}}" data-category="{{- .Site.Params.GiscusCategory -}}"
data-category-id="{{- .Site.Params.GiscusCategoryId -}}" data-mapping="{{ $mapping }}" data-strict="0"
data-reactions-enabled="1" data-emit-metadata="0" data-input-position="bottom" data-theme="{{ $theme }}"
data-lang="{{ $language }}" crossorigin="anonymous" {{ if $lazyload }} data-loading="lazy" {{ end }}
async></script>
2024-04-09 14:03:09 +02:00
*/}}