feat: add Button block & page background option

This commit is contained in:
George Cushen committed 2023-10-29 09:18:33 +00:00
1 parent 41d716f8ed
commit 0f56496291
11 files changed
+241 -95

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@ jobs:
- local_path: 'course'
split_repository: 'starter-hugo-online-course'
- local_path: 'minimal'
split_repository: 'hugo-minimal-theme'
split_repository: 'hugo-link-in-bio-theme'
- local_path: 'research-group'
split_repository: 'starter-hugo-research-group'
- local_path: 'second-brain'
@@ -70,3 +70,13 @@
color: #fff;
text-decoration: none;
}
#page-bg {
position: fixed;
left: 0;
right: 0;
height: 100%;
width: 100%;
z-index: -1;
display: block;
}
@@ -0,0 +1,55 @@
// Wowchemy Light / Dark theme toggle
document.addEventListener('DOMContentLoaded', function () {
addThemeToggleListener();
});
function addThemeToggleListener() {
const defaultTheme = window.wowchemy.defaultTheme;
const themeToggleButtons = document.querySelectorAll(".theme-toggle");
// Change the icons of the buttons based on previous settings or system theme
if (
localStorage.getItem("wc-color-theme") === "dark" ||
(!("wc-color-theme" in localStorage) &&
((window.matchMedia("(prefers-color-scheme: dark)").matches && defaultTheme === "system") || defaultTheme === "dark"))
) {
themeToggleButtons.forEach((el) => el.dataset.theme = "dark");
} else {
themeToggleButtons.forEach((el) => el.dataset.theme = "light");
}
// Add click event handler to the light/dark buttons
themeToggleButtons.forEach((el) => {
el.addEventListener("click", function () {
console.debug('Theme toggled');
if (localStorage.getItem("wc-color-theme")) {
if (localStorage.getItem("wc-color-theme") === "light") {
window.wowchemy.setDarkTheme();
localStorage.setItem("wc-color-theme", "dark");
} else {
window.wowchemy.setLightTheme();
localStorage.setItem("wc-color-theme", "light");
}
} else {
if (document.documentElement.classList.contains("dark")) {
window.wowchemy.setLightTheme();
localStorage.setItem("wc-color-theme", "light");
} else {
window.wowchemy.setDarkTheme();
localStorage.setItem("wc-color-theme", "dark");
}
}
el.dataset.theme = document.documentElement.classList.contains("dark") ? "dark" : "light";
});
});
// Listen for dark mode toggling in OS
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (event) => {
if (defaultTheme === "system" && !("wc-color-theme" in localStorage)) {
event.matches ? window.wowchemy.setDarkTheme() : window.wowchemy.setLightTheme();
themeToggleButtons.forEach((el) =>
el.dataset.theme = document.documentElement.classList.contains("dark") ? "dark" : "light"
);
}
});
}
+6 -1
View File
@@ -16,6 +16,9 @@ cv: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="cu
graduation-cap: <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M4.26 10.147a60.436 60.436 0 00-.491 6.347A48.627 48.627 0 0112 20.904a48.627 48.627 0 018.232-4.41 60.46 60.46 0 00-.491-6.347m-15.482 0a50.57 50.57 0 00-2.658-.813A59.905 59.905 0 0112 3.493a59.902 59.902 0 0110.399 5.84c-.896.248-1.783.52-2.658.814m-15.482 0A50.697 50.697 0 0112 13.489a50.702 50.702 0 017.74-3.342M6.75 15a.75.75 0 100-1.5.75.75 0 000 1.5zm0 0v-3.675A55.378 55.378 0 0112 8.443m-7.007 11.55A5.981 5.981 0 006.75 15.75v-1.5" />
</svg>
arxiv: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><g style="stroke-width:.645161"><path fill="currentColor" d="M119.65 351.996a14.333 14.333 0 0 1-13.502-8.676c-2.196-5.27-.62-8.967 4.197-15.865 7.055-10.38 78.824-96.562 78.824-96.562l-15.882-14.864c-13.381-13.378-13.956-31.333-1.51-43.775l18.492-17.613-51.598-63.377c-4.005-4.268-6.485-11.756-4.248-17.131a14.643 14.643 0 0 1 13.684-9.07 13.05 13.05 0 0 1 9.838 4.86l61.369 57.057 94.576-90.07A17.51 17.51 0 0 1 325.773 32c1.604.004 3.198.245 4.732.715a17.844 17.844 0 0 1 11.871 12.252 16.52 16.52 0 0 1-4.181 15.283l-83.086 100.012 14.879 13.834c11.096 10.003 11.154 27.39.127 37.469l-16.295 15.63 56.256 66.444.074.086.066.09c5.028 6.531 7.432 11.561 4.84 17.94a23.335 23.335 0 0 1-15.256 11.85c-.676.092-1.36.137-2.043.138l-.004-.012a18.402 18.402 0 0 1-11.775-5.24l-.13-.108-.124-.111-65.207-59.127-89.896 86.24s-5.334 6.478-10.971 6.611zm178.104-33.041a11.33 11.33 0 0 0 1.432-.096 18.907 18.907 0 0 0 11.431-8.91c1.45-3.562 1.003-6.457-4.197-13.215l-56.059-66.218-26.375 25.302 64.955 58.906a14.045 14.045 0 0 0 8.813 4.217v.014zm-105.318-91.553 142.01-170.158c2.787-3.49 4.53-6.98 3.342-10.912a13.062 13.062 0 0 0-8.686-9.057 11.366 11.366 0 0 0-3.336-.506 12.77 12.77 0 0 0-8.576 3.588L175.157 175.642c-11.172 11.172-9.482 26.02 1.393 36.895z" style="stroke-width:.416233" transform="matrix(1.55 0 0 -1.55 -123.2 553.6)"/></g></svg>
google-scholar: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M343.759 106.662V79.43L363.524 64h-213.89L20.476 176.274h85.656a82.339 82.339 0 0 0-.219 6.225c0 20.845 7.22 38.087 21.672 51.861 14.453 13.797 32.252 20.648 53.327 20.648 4.923 0 9.75-.368 14.438-1.024-2.907 6.5-4.374 12.523-4.374 18.142 0 9.875 4.499 20.43 13.467 31.642-39.234 2.67-68.061 9.732-86.437 21.163-10.531 6.5-19 14.704-25.39 24.531-6.391 9.9-9.578 20.515-9.578 31.962 0 9.648 2.062 18.336 6.219 26.062 4.156 7.726 9.578 14.07 16.312 18.984 6.718 4.968 14.469 9.101 23.219 12.469 8.734 3.344 17.406 5.718 26.061 7.062A167.052 167.052 0 0 0 180.555 448c13.469 0 26.953-1.734 40.547-5.187 13.562-3.485 26.28-8.642 38.171-15.493 11.86-6.805 21.515-16.086 28.922-27.718 7.39-11.68 11.094-24.805 11.094-39.336 0-11.016-2.25-21.039-6.75-30.14-4.468-9.073-9.938-16.542-16.452-22.345-6.501-5.813-13-11.155-19.516-15.968-6.5-4.845-12-9.75-16.468-14.813-4.485-5.046-6.735-10.054-6.735-14.984 0-4.921 1.734-9.672 5.216-14.265 3.455-4.61 7.674-9.048 12.61-13.306 4.937-4.25 9.875-8.968 14.796-14.133 4.922-5.147 9.141-11.827 12.61-20.008 3.485-8.18 5.203-17.445 5.203-27.757 0-13.453-2.547-24.46-7.547-33.314-.594-1.022-1.218-1.803-1.875-3.022l56.907-46.672v17.119c-7.393.93-6.624 5.345-6.624 10.635V245.96c0 5.958 4.875 10.834 10.834 10.834h3.989c5.958 0 10.833-4.875 10.833-10.834V117.293c0-5.277.778-9.688-6.561-10.63zm-107.36 222.48c1.14.75 3.704 2.78 7.718 6.038 4.05 3.243 6.797 5.695 8.266 7.414a443.553 443.553 0 0 1 6.376 7.547c2.813 3.375 4.718 6.304 5.718 8.734 1 2.477 2.016 5.461 3.047 8.946a38.27 38.27 0 0 1 1.485 10.562c0 17.048-6.564 29.68-19.656 37.859-13.125 8.18-28.767 12.274-46.938 12.274-9.187 0-18.203-1.093-27.063-3.196-8.843-2.116-17.311-5.336-25.39-9.601-8.078-4.258-14.577-10.204-19.5-17.797-4.938-7.64-7.407-16.415-7.407-26.25 0-10.32 2.797-19.29 8.422-26.906 5.594-7.625 12.938-13.391 22.032-17.315 9.063-3.946 18.25-6.742 27.562-8.398a157.865 157.865 0 0 1 28.438-2.555c4.47 0 7.936.25 10.405.696.455.219 3.032 2.07 7.735 5.563 4.704 3.462 7.625 5.595 8.75 6.384zm-3.359-100.579c-7.406 8.86-17.734 13.288-30.953 13.288-11.86 0-22.298-4.764-31.266-14.312-9-9.523-15.422-20.328-19.344-32.43-3.937-12.109-5.906-23.984-5.906-35.648 0-13.694 3.596-25.352 10.781-34.976 7.187-9.65 17.5-14.485 30.938-14.485 11.875 0 22.374 5.038 31.437 15.157 9.094 10.085 15.61 21.413 19.517 33.968 3.922 12.54 5.873 24.53 5.873 35.984 0 13.446-3.702 24.61-11.076 33.454z" style="stroke-width:.0647871"/></svg>
orcid: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M336.62 194.538c-7.13-3.328-13.866-5.56-20.253-6.614-6.365-1.095-16.574-1.612-30.71-1.612h-36.704v152.747h37.634c14.673 0 26.081-1.013 34.224-3.017 8.142-2.004 14.921-4.526 20.356-7.626a69.448 69.448 0 0 0 14.942-11.388c14.488-14.714 21.742-33.273 21.742-55.717 0-22.052-7.44-40.052-22.341-53.982-5.498-5.166-11.822-9.444-18.89-12.793zM256 8C119.022 8 8 119.042 8 256s111.022 248 248 248 248-111.042 248-248S392.978 8 256 8Zm-82.336 357.513h-29.389V160.148h29.389zM158.95 138.696c-11.14 0-20.213-9.01-20.213-20.212 0-11.118 9.052-20.191 20.213-20.191 11.18 0 20.232 9.052 20.232 20.191a20.194 20.194 0 0 1-20.232 20.212zm241.386 163.597c-5.29 12.545-12.834 23.581-22.65 33.088-9.982 9.837-21.597 17.194-34.844 22.196-7.75 3.017-14.839 5.063-21.307 6.117-6.49 1.013-18.828 1.509-37.076 1.509h-64.956V160.148h69.233c27.962 0 50.034 4.154 66.32 12.545 16.265 8.37 29.181 20.728 38.792 36.972 9.61 16.265 14.425 34.018 14.425 53.196.023 13.765-2.666 26.908-7.936 39.432z" style="stroke-width:.07717"/></svg>
# Email
send: <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
@@ -32,5 +35,7 @@ information-circle: <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox=
exclamation-triangle: <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" /></svg>
# Skills
python: <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512" fill="currentColor"><path d="M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"/></svg>
# Wowchemy/Hugo
hugo: <svg viewBox="0 0 370 391" xmlns="http://www.w3.org/2000/svg"><g clip-rule="evenodd" fill-rule="evenodd"><path d="m207.5 22.4 114.4 66.6c13.5 7.9 21.9 22.4 21.9 38v136.4c0 17.3-9.3 33.3-24.5 41.8l-113.5 63.9a49.06 49.06 0 0 1 -48.5-.2l-104.5-60.1c-16.4-9.5-26.6-27-26.6-45.9v-129.5c0-19.1 9.9-36.8 26.1-46.8l102.8-63.5c16-9.9 36.2-10.1 52.4-.7z" fill="#ff4088" stroke="#c9177e" stroke-width="27" /><path d="m105.6 298.2v-207.2h43.4v75.5h71.9v-75.5h43.5v207.2h-43.5v-90.6h-71.9v90.6z" fill="#fff" /></g></svg>
@@ -2,11 +2,15 @@
{{ "<!-- This site was created with Wowchemy. https://www.wowchemy.com -->" | safeHTML }}
{{ printf "<!-- Last Published: %s -->" (now | time.Format ":date_long") | safeHTML }}
{{- $language_code := site.LanguageCode | default "en-us" -}}
<html lang="{{$language_code}}" {{ if in site.Data.i18n.rtl.rtl $language_code }}dir="rtl"{{end}}>
<html lang="{{$language_code}}" {{ if in site.Data.i18n.rtl.rtl $language_code }}dir="rtl"{{end}}
data-wc-theme-default="{{ site.Params.appearance.theme_default | default "system" }}">
{{ partial "site_head" . }}
<body class="dark:bg-gray-800 dark:text-white-800 page-wrapper">
<div id="page-bg"></div>
<div class="page-header">
{{ partial "navbar" . }}
{{ if (site.Params.header.navbar.enable | default true) }}
{{ partial "navbar" . }}
{{ end }}
</div>
<div class="page-body my-10">
{{ block "main" . }}{{ end }}
@@ -14,5 +18,8 @@
<div class="page-footer">
{{ partial "site_footer" . }}
</div>
{{/* EXTENSIBILITY HOOK: BODY-END */}}
{{ partial "functions/get_hook" (dict "hook" "body-end" "context" .) }}
</body>
</html>
@@ -71,7 +71,7 @@
<li>
<a href="{{ $link | safeURL }}" {{ $target | safeHTMLAttr }} aria-label="{{ .icon }}"
{{ with .label }} data-toggle="tooltip" data-placement="top" title="{{.}}"{{ end }}>
{{ partial "functions/get_icon" (dict "name" .icon "attributes" "height=1.5rem") }}
{{ partial "functions/get_icon" (dict "name" .icon "attributes" "style=\"height: 1.5rem;\"") }}
</a>
</li>
{{ end }}
@@ -0,0 +1,26 @@
{{/* Wowchemy Blocks: Buttons */}}
{{/* Documentation: https://wowchemy.com/blocks/ */}}
{{/* License: https://github.com/wowchemy/wowchemy-hugo-themes/blob/main/LICENSE.md */}}
{{/* Initialise */}}
{{ $page := .wcPage }}
{{ $block := .wcBlock }}
<div class="flex items-center flex-col mx-auto w-full justify-center mt-4 px-8 pb-5">
{{ range $index, $item := $block.content.buttons }}
<a href="{{ .url }}" target="_blank" rel="noopener noreferrer" class="flex items-center p-1 w-full rounded-md hover:scale-105 transition-all bg-gray-100 mb-3 max-w-3xl">
<div class="flex text-center w-full">
<div class="w-10 h-10 text-gray-700">
{{ with .icon }}
{{ partial "functions/get_icon" (dict "name" . "attributes" "height=\"40\" width=\"40\" class=\"rounded-sm\"") }}
{{ end }}
</div>
<div class="flex justify-center items-center font-semibold w-full text-gray-700 -ml-10">
{{ .title | markdownify | emojify }}
</div>
</div>
</a>
{{end}}
</div>
@@ -0,0 +1,30 @@
{{ if .IsTranslated | and site.Params.footer.show_translations }}
<div class="powered-by d-flex flex-wrap pb-2 justify-content-center">
<div class="p-2 font-weight-bold"><i class="fas fa-globe pr-1" aria-hidden="true"></i>{{ i18n "languages" }}:</div>
<div class="p-2">{{ index site.Data.i18n.languages .Lang }}</div>
{{ range .Translations }}
<div class="p-2"><a href="{{ .Permalink }}">{{ index site.Data.i18n.languages .Lang }}</a></div>
{{ end }}
</div>
{{ end }}
{{ if or (site.GetPage "/terms.md") (site.GetPage "/privacy.md") }}
<p class="text-center">
{{ with site.GetPage "/privacy.md" }}
{{ printf "<a href=\"%s\">%s</a>" .RelPermalink .Title | safeHTML }}
{{ end }}
{{ with site.GetPage "/terms.md" }}
{{ if site.GetPage "/privacy.md" }} &middot; {{ end }}
{{ printf "<a href=\"%s\">%s</a>" .RelPermalink .Title | safeHTML }}
{{ end }}
</p>
{{ end }}
{{ with site.Params.footer.text }}
<p class="text-center">
{{ . | markdownify | emojify }}
</p>
{{ end }}
{{/* Display copyright license. */}}
{{ partial "site_footer_license" . }}
@@ -1,26 +1,16 @@
<footer class="text-sm leading-6 mt-12 mb-4 text-slate-700 flex justify-center dark:text-slate-200">
<footer class="container mx-auto flex flex-col justify-items-center text-sm leading-6 mt-12 mb-4 text-slate-700 dark:text-slate-200">
{{ partial "functions/get_hook" (dict "hook" "footer-start" "context" .) }}
{{ if or (site.GetPage "/terms.md") (site.GetPage "/privacy.md") }}
<p>
{{ with site.GetPage "/privacy.md" }}
{{ printf "<a href=\"%s\">%s</a>" .RelPermalink .Title | safeHTML }}
{{ end }}
{{ with site.GetPage "/terms.md" }}
{{ if site.GetPage "/privacy.md" }} &middot; {{ end }}
{{ printf "<a href=\"%s\">%s</a>" .RelPermalink .Title | safeHTML }}
{{ end }}
</p>
{{/* Load footer block */}}
{{ $footer_section_name := site.Params.footer.block | default "minimal" }}
{{ $footer_section_path := printf "components/footers/%s.html" $footer_section_name }}
{{ if not (templates.Exists (printf "partials/%s" $footer_section_path)) }}
{{ errorf "Check your `params.yaml`. Cannot find footer block at `layouts/partials/%s`" $footer_section_path }}
{{ end }}
{{ partial $footer_section_path . }}
{{ with site.Params.footer.text }}
<p>
{{ . | markdownify | emojify }}
</p>
{{ end }}
<p>
<p class="powered-by text-center">
{{ $is_sponsor := site.Params.i_am_a_sponsor | default false }}
{{ $hide_published_with_footer := site.Params.power_ups.hide_published_with | default true }}
{{ if not (and $is_sponsor $hide_published_with_footer) }}
@@ -33,7 +23,8 @@
{{ $i18n_published_with = replace $i18n_published_with "{wowchemy}" "<a href=\"https://wowchemy.com/?utm_campaign=poweredby\" target=\"_blank\" rel=\"noopener\">Wowchemy</a>" | safeHTML }}
{{ $i18n_published_with = replace $i18n_published_with "{repo_link}" "<a href=\"https://github.com/wowchemy/wowchemy-hugo-themes\" target=\"_blank\" rel=\"noopener\">" | safeHTML }}
{{ $i18n_published_with = replace $i18n_published_with "{/repo_link}" "</a>" | safeHTML }}
{{ $i18n_published_with | markdownify | emojify | safeHTML }}
{{ $i18n_published_with | replaceRE "{year}" now.Year | markdownify | emojify | safeHTML }}
{{ end }}
</p>
</footer>
@@ -0,0 +1,53 @@
{{/* Display copyright license. */}}
{{ $copyright_license := .Params.copyright.license | default site.Params.footer.copyright.license }}
{{ $notice := .Params.copyright.notice | default site.Params.footer.copyright.notice }}
{{ if ($copyright_license.enable | default false) }}
{{ $allow_commercial := $copyright_license.allow_commercial | default false }}
{{ $allow_derivatives := $copyright_license.allow_derivatives | default false }}
{{ $share_alike := $copyright_license.share_alike | default true }}
{{ $cc_code := "by" }}
{{ if not $allow_commercial }}
{{ $cc_code = printf "%s-nc" $cc_code }}
{{end}}
{{ if and $allow_derivatives $share_alike }}
{{ $cc_code = printf "%s-sa" $cc_code }}
{{ else if not $allow_derivatives }}
{{ $cc_code = printf "%s-nd" $cc_code }}
{{end}}
{{ $license_url := printf "https://creativecommons.org/licenses/%s/4.0" ($cc_code | urlize) }}
{{ with $notice }}
<p class="powered-by text-center">
{{ replace (replace . "{year}" now.Year) "{license}" (printf "<a href=\"%s\" rel=\"noopener noreferrer\" target=\"_blank\">CC %s 4.0</a>" $license_url (replace $cc_code "-" " " | upper)) | markdownify }}
</p>
{{ end }}
<p class="powered-by footer-license-icons">
<a href="{{$license_url}}" rel="noopener noreferrer" target="_blank" aria-label="Creative Commons">
<i class="fab fa-creative-commons fa-2x" aria-hidden="true"></i>
<i class="fab fa-creative-commons-by fa-2x" aria-hidden="true"></i>
{{ if not $allow_commercial }}
<i class="fab fa-creative-commons-nc fa-2x" aria-hidden="true"></i>
{{end}}
{{ if and $allow_derivatives $share_alike }}
<i class="fab fa-creative-commons-sa fa-2x" aria-hidden="true"></i>
{{ else if not $allow_derivatives }}
<i class="fab fa-creative-commons-nd fa-2x" aria-hidden="true"></i>
{{end}}
</a>
</p>
{{ else }}
{{ with $notice }}
<p class="powered-by text-center">
{{ replace . "{year}" now.Year | markdownify }}
</p>
{{ end }}
{{ end }}
@@ -60,81 +60,33 @@
{{ end }}
<script>
/* Light/dark mode */
const defaultMode = 'system';
/* Wowchemy JS Global Init */
window.wowchemy = {
defaultTheme: document.documentElement.dataset.wcThemeDefault,
setDarkTheme: () => {
document.documentElement.classList.add("dark");
document.documentElement.style.colorScheme = "dark";
},
setLightTheme: () => {
document.documentElement.classList.remove("dark");
document.documentElement.style.colorScheme = "light";
}
}
const setDarkMode = () => {
document.documentElement.classList.add("dark");
document.documentElement.style.colorScheme = "dark";
}
const setLightMode = () => {
document.documentElement.classList.remove("dark");
document.documentElement.style.colorScheme = "light";
}
console.debug(`Default Wowchemy theme is ${window.wowchemy.defaultTheme}`);
if ("wc-color-theme" in localStorage) {
localStorage.getItem("wc-color-theme") === "dark" ? setDarkMode() : setLightMode();
localStorage.getItem("wc-color-theme") === "dark" ? window.wowchemy.setDarkTheme() : window.wowchemy.setLightTheme();
} else {
defaultMode === "dark" ? setDarkMode() : setLightMode();
if (defaultMode === "system") {
window.matchMedia("(prefers-color-scheme: dark)").matches ? setDarkMode() : setLightMode();
window.wowchemy.defaultTheme === "dark" ? window.wowchemy.setDarkTheme() : window.wowchemy.setLightTheme();
if (window.wowchemy.defaultTheme === "system") {
window.matchMedia("(prefers-color-scheme: dark)").matches ? window.wowchemy.setDarkTheme() : window.wowchemy.setLightTheme();
}
}
document.addEventListener('DOMContentLoaded', function () {
const defaultMode = 'system'
const themeToggleButtons = document.querySelectorAll(".theme-toggle");
// Check previous theme settings or system theme, and update current theme button appropriately
if (
localStorage.getItem("wc-color-theme") === "dark" ||
(!("wc-color-theme" in localStorage) &&
((window.matchMedia("(prefers-color-scheme: dark)").matches && defaultMode === "system") || defaultMode === "dark"))
) {
themeToggleButtons.forEach((el) => el.dataset.theme = "dark");
} else {
themeToggleButtons.forEach((el) => el.dataset.theme = "light");
}
// Add click event handler to the light/dark buttons
themeToggleButtons.forEach((el) => {
el.addEventListener("click", function () {
console.debug('Theme toggled');
if (localStorage.getItem("wc-color-theme")) {
if (localStorage.getItem("wc-color-theme") === "light") {
setDarkMode();
localStorage.setItem("wc-color-theme", "dark");
} else {
setLightMode();
localStorage.setItem("wc-color-theme", "light");
}
} else {
if (document.documentElement.classList.contains("dark")) {
setLightMode();
localStorage.setItem("wc-color-theme", "light");
} else {
setDarkMode();
localStorage.setItem("wc-color-theme", "dark");
}
}
el.dataset.theme = document.documentElement.classList.contains("dark") ? "dark" : "light";
});
});
// Listen for system color theme changes
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
if (defaultMode === "system" && !("wc-color-theme" in localStorage)) {
e.matches ? setDarkMode() : setLightMode();
themeToggleButtons.forEach((el) =>
el.dataset.theme = document.documentElement.classList.contains("dark") ? "dark" : "light"
);
}
});
});
</script>
<script>
// Apply Hugo style fixes
document.addEventListener('DOMContentLoaded', function () {
// Fix Hugo task list style
let checkboxes = document.querySelectorAll('li input[type=\'checkbox\'][disabled]');
@@ -276,6 +228,26 @@
}
</style>
{{ if .Params.design.background.image.filename }}
{{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
{{ $bg_img := resources.Get (printf "media/%s" .Params.design.background.image.filename) }}
{{ if $bg_img }}
{{/* Exception for SVG as Hugo doesn't yet support image processing on SVG. */}}
{{ if ne $bg_img.MediaType.SubType "svg" }}
{{ $bg_img = $bg_img.Fit "1920x1920 webp" }}
{{ end }}
<style>
#page-bg {
background-image: url('{{$bg_img.Permalink}}');
background-position: center;
background-size: cover;
}
</style>
{{ else }}
{{ errorf "Couldn't find page background `%s` in the `assets/media/` folder - please add it." .Params.design.background.image.filename }}
{{ end }}
{{ end }}
{{/* Init prior to auto-chunking/bundling scripts due to Hugo concurrency issues */}}
{{- partialCached "init.html" . -}}
@@ -290,7 +262,8 @@
{{ $js_params := dict "hugoEnvironment" hugo.Environment "i18n" $i18n }}
{{ $js_academic := resources.Get "js/wowchemy-code-copy.js" | js.Build (dict "targetPath" (printf "js/wow-core-%s.js" .Lang ) "params" $js_params) }}
{{ $js_academic := $js_academic | resources.Minify }}
{{ $js_bundle := slice $js_bundle_head $js_academic | resources.Concat (printf "js/wowchemy-%s.min.js" .Lang) }}
{{- $js_theme := resources.Get "js/wowchemy-theme.js" | resources.Minify -}}
{{ $js_bundle := slice $js_bundle_head $js_academic $js_theme | resources.Concat (printf "js/wowchemy-%s.min.js" .Lang) }}
{{- if hugo.IsProduction -}}
{{ $js_bundle = $js_bundle | fingerprint "sha256" }}
{{- end -}}
@@ -301,9 +274,5 @@
></script>
{{/* EXTENSIBILITY HOOK: HEAD-END */}}
{{/* Deprecated custom_head hook */}}
{{ if templates.Exists "partials/custom_head" }}
{{ partial "custom_head" . }}
{{ end }}
{{ partial "functions/get_hook" (dict "hook" "head-end" "context" .) }}
</head>