Move single page scripts to a scripts block

This commit is contained in:
Eryn Wells 2022-09-26 13:21:43 -07:00
parent c47444925c
commit 16201877f4
4 changed files with 17 additions and 29 deletions

View file

@ -9,18 +9,5 @@
{{ partial "footer.html" . }}
</body>
<script>
const bodyClasses = document.body.classList;
const systemDarkModeMatch = window.matchMedia('(prefers-color-scheme: dark)');
const localStorageDarkMode = localStorage.getItem('dark');
const setDark = isDark => {
bodyClasses[isDark ? 'add' : 'remove']('dark');
localStorage.setItem('dark', isDark ? 'yes' : 'no');
};
setDark(localStorageDarkMode ? localStorageDarkMode === 'yes' : systemDarkModeMatch.matches);
requestAnimationFrame(() => bodyClasses.remove('not-ready'));
systemDarkModeMatch.addEventListener('change', (event) => setDark(event.matches));
</script>
{{ block "scripts" . }}{{ end }}
</html>

View file

@ -35,3 +35,7 @@
{{ end }}
</article>
{{ end }}
{{ define "scripts" }}
{{ partial "single_scripts.html" . }}
{{ end }}