From 3c5be0854d51db388a30f80a6f322e1eaad9d357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Sat, 25 Feb 2023 19:14:28 +0000 Subject: [PATCH] :sparkles: add support for meta theme-color with bg color --- assets/js/appearance.js | 17 ++++++++++++++++- layouts/partials/head.html | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/js/appearance.js b/assets/js/appearance.js index af3e41b9..d5b1b053 100644 --- a/assets/js/appearance.js +++ b/assets/js/appearance.js @@ -26,6 +26,8 @@ window.addEventListener("DOMContentLoaded", (event) => { const switcher = document.getElementById("appearance-switcher"); const switcherMobile = document.getElementById("appearance-switcher-mobile"); + updateMeta() + if (switcher) { switcher.addEventListener("click", () => { document.documentElement.classList.toggle("dark"); @@ -33,6 +35,7 @@ window.addEventListener("DOMContentLoaded", (event) => { "appearance", document.documentElement.classList.contains("dark") ? "dark" : "light" ); + updateMeta() }); switcher.addEventListener("contextmenu", (event) => { event.preventDefault(); @@ -46,10 +49,22 @@ window.addEventListener("DOMContentLoaded", (event) => { "appearance", document.documentElement.classList.contains("dark") ? "dark" : "light" ); + updateMeta() }); switcherMobile.addEventListener("contextmenu", (event) => { event.preventDefault(); localStorage.removeItem("appearance"); }); } -}); \ No newline at end of file +}); + + +var updateMeta = () => { + var elem, style; + elem = document.querySelector('body'); + console.log(elem) + style = getComputedStyle(elem); + console.log(style.backgroundColor) + + document.querySelector('meta[name="theme-color"]').setAttribute('content', style.backgroundColor); +} \ No newline at end of file diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 327b2d59..e1917c31 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -118,7 +118,7 @@ {{ if templates.Exists "partials/extend-head.html" }} {{ partialCached "extend-head.html" .Site }} {{ end }} - + {{/* Firebase */}} {{ with $.Site.Params.firebase }} {{ if isset $.Site.Params "firebase" }}