Skip to content

Commit

Permalink
🚸 Set theme-color using theme colour scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
jpanther committed Nov 21, 2022
1 parent 4679ce4 commit 447ce2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions assets/js/appearance.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const sitePreference = document.documentElement.getAttribute("data-default-appearance");
const userPreference = localStorage.getItem("appearance");

function getCSSValue(varName) {
var cssValue = window.getComputedStyle(document.documentElement).getPropertyValue(varName);
return "rgb(" + cssValue.replace(/\s+/g, "") + ")";
}

function setThemeColor() {
const metaThemeColor = document.querySelector("meta[name=theme-color]");
var metaThemeColor = document.querySelector("meta[name=theme-color]");
document.documentElement.classList.contains("dark")
? metaThemeColor.setAttribute("content", "#27272a")
: metaThemeColor.setAttribute("content", "#ffffff");
? metaThemeColor.setAttribute("content", getCSSValue("--color-neutral-800"))
: metaThemeColor.setAttribute("content", getCSSValue("--color-neutral"));
return true;
}

if ((sitePreference === "dark" && userPreference === null) || userPreference === "dark") {
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="content-language" content="{{ . }}" />
{{ end }}
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#ffffff" />
<meta name="theme-color" content="rgb(255,255,255)" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
{{/* Title */}}
{{ if .IsHome -}}
Expand Down

0 comments on commit 447ce2f

Please sign in to comment.