diff --git a/static/fonts/OpenDyslexic-Mono.otf b/static/fonts/OpenDyslexic-Mono.otf new file mode 100644 index 00000000..543d46be Binary files /dev/null and b/static/fonts/OpenDyslexic-Mono.otf differ diff --git a/static/fonts/OpenDyslexic-Regular.woff2 b/static/fonts/OpenDyslexic-Regular.woff2 new file mode 100644 index 00000000..47e26d82 Binary files /dev/null and b/static/fonts/OpenDyslexic-Regular.woff2 differ diff --git a/themes/hextra/assets/css/custom.css b/themes/hextra/assets/css/custom.css index 908cf770..cf83829e 100644 --- a/themes/hextra/assets/css/custom.css +++ b/themes/hextra/assets/css/custom.css @@ -45,3 +45,17 @@ article a[href^="https://"]::after display: none; } /* ---------------------------------------------------------------- */ + + + +/* Import OpenDyslexic for font toggle. */ +/* ------------------------------------ */ +@font-face { + font-family: Open-Dyslexic; + src: url(/fonts/OpenDyslexic-Regular.woff2); +} +@font-face { + font-family: Open-Dyslexic-Mono; + src: url(/fonts/OpenDyslexic-Mono.otf); +} +/* ------------------------------------ */ diff --git a/themes/hextra/assets/js/toggle-font.js b/themes/hextra/assets/js/toggle-font.js new file mode 100644 index 00000000..00f3a129 --- /dev/null +++ b/themes/hextra/assets/js/toggle-font.js @@ -0,0 +1,43 @@ +var contentElements = document.querySelectorAll('body'); +var preElements = document.querySelectorAll('pre'); + +function toggleFont() { + var currentFont = localStorage.getItem('currentFont') || 'default'; + + if (currentFont === 'default') { + setDyslexicFonts(); + localStorage.setItem('currentFont', 'dyslexic'); + } else { + setDefaultFonts(); + localStorage.setItem('currentFont', 'default'); + } +} + +function setDyslexicFonts() { + contentElements.forEach(function(element) { + element.style.fontFamily = 'Open-Dyslexic'; + }); + preElements.forEach(function(element) { + element.style.fontFamily = 'Open-Dyslexic-Mono'; + }); + console.log("Switch to Open-Dyslexic and Open-Dyslexic-Mono for pre tags."); +} + +function setDefaultFonts() { + contentElements.forEach(function(element) { + element.style.fontFamily = 'sans-serif'; + }); + preElements.forEach(function(element) { + element.style.fontFamily = 'monospace'; + }); + console.log("Switch to sans-serif and monospace for pre tags."); +} + +document.addEventListener('DOMContentLoaded', function() { + var savedFont = localStorage.getItem('currentFont'); + if (savedFont === 'dyslexic') { + setDyslexicFonts(); + } else { + setDefaultFonts(); + } +}); diff --git a/themes/hextra/layouts/partials/font-toggle.html b/themes/hextra/layouts/partials/font-toggle.html new file mode 100644 index 00000000..3ef8c87e --- /dev/null +++ b/themes/hextra/layouts/partials/font-toggle.html @@ -0,0 +1,21 @@ +{{- $hideLabel := .hideLabel | default false -}} +{{- $changeFont := (T "changeFont") | default "Change font" -}} +{{- $light := (T "light") | default "Light" -}} +{{- $dark := (T "dark") | default "Dark" -}} + + + diff --git a/themes/hextra/layouts/partials/scripts.html b/themes/hextra/layouts/partials/scripts.html index c6593c63..1c0c2ef9 100644 --- a/themes/hextra/layouts/partials/scripts.html +++ b/themes/hextra/layouts/partials/scripts.html @@ -6,14 +6,14 @@ {{- $jsFileTree := resources.Get "js/filetree.js" -}} {{- $jsSidebar := resources.Get "js/sidebar.js" -}} {{- $jsBackToTop := resources.Get "js/back-to-top.js" -}} +{{- $jsToggleFont := resources.Get "js/toggle-font.js" -}} -{{- $scripts := slice $jsTheme $jsMenu $jsCodeCopy $jsTabs $jsLang $jsFileTree $jsSidebar $jsBackToTop | resources.Concat "js/main.js" -}} +{{- $scripts := slice $jsTheme $jsMenu $jsCodeCopy $jsTabs $jsLang $jsFileTree $jsSidebar $jsBackToTop $jsToggleFont | resources.Concat "js/main.js" -}} {{- if hugo.IsProduction -}} {{- $scripts = $scripts | minify | fingerprint -}} {{- end -}} - {{/* Search */}} {{- if (site.Params.search.enable | default true) -}} {{- $searchType := site.Params.search.type | default "flexsearch" -}} diff --git a/themes/hextra/layouts/partials/sidebar.html b/themes/hextra/layouts/partials/sidebar.html index e00e4315..28bd4896 100644 --- a/themes/hextra/layouts/partials/sidebar.html +++ b/themes/hextra/layouts/partials/sidebar.html @@ -53,6 +53,7 @@
{{ partial "theme-toggle" }}
{{- end -}} {{- end -}} +
{{ partial "font-toggle" }}
{{- end -}} diff --git a/themes/hextra/static/fonts/OpenDyslexic-Regular.woff2 b/themes/hextra/static/fonts/OpenDyslexic-Regular.woff2 new file mode 100644 index 00000000..47e26d82 Binary files /dev/null and b/themes/hextra/static/fonts/OpenDyslexic-Regular.woff2 differ