feat: update theme-color tag on theme switch

This commit is contained in:
satnaing
2023-09-14 11:53:46 +06:30
committed by Sat Naing
parent 87b3e5b8cd
commit f25377674e
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -27,6 +27,23 @@ function reflectPreference() {
document.firstElementChild.setAttribute("data-theme", themeValue);
document.querySelector("#theme-btn")?.setAttribute("aria-label", themeValue);
// Get a reference to the body element
const body = document.body;
// Check if the body element exists before using getComputedStyle
if (body) {
// Get the computed styles for the body element
const computedStyles = window.getComputedStyle(body);
// Get the background color property
const bgColor = computedStyles.backgroundColor;
// Set the background color in <meta theme-color ... />
document
.querySelector("meta[name='theme-color']")
?.setAttribute("content", bgColor);
}
}
// set early so no page flashes / CSS is made aware
+2
View File
@@ -63,6 +63,8 @@ const socialImageURL = new URL(
rel="stylesheet"
/>
<meta name="theme-color" content="" />
{
// If PUBLIC_GOOGLE_SITE_VERIFICATION is set in the environment variable,
// include google-site-verification tag in the heading