From 86a584e46503c9fd77f40ffa99d0bd4ce32afb02 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 10 Oct 2024 23:17:20 +0300 Subject: [PATCH] fix remark42 theme --- layouts/partials/footer_custom.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/layouts/partials/footer_custom.html b/layouts/partials/footer_custom.html index 78a9225..c3ef23b 100644 --- a/layouts/partials/footer_custom.html +++ b/layouts/partials/footer_custom.html @@ -10,6 +10,10 @@ theme: 'light' }; + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + remark_config.theme = "dark"; + } + (function(c) { for(var i = 0; i < c.length; i++){ var d = document, s = d.createElement('script'); @@ -18,6 +22,11 @@ (d.head || d.body).appendChild(s); } })(remark_config.components || ['embed']); + + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { + const newColorScheme = event.matches ? "dark" : "light"; + window.REMARK42.changeTheme(newColorScheme); + }); {{ end }} {{ end }}