Move single page scripts to a scripts block
This commit is contained in:
parent
c47444925c
commit
16201877f4
4 changed files with 17 additions and 29 deletions
|
@ -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>
|
||||
|
|
|
@ -35,3 +35,7 @@
|
|||
{{ end }}
|
||||
</article>
|
||||
{{ end }}
|
||||
|
||||
{{ define "scripts" }}
|
||||
{{ partial "single_scripts.html" . }}
|
||||
{{ end }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue