Ensure color-scheme meta tag is set

This commit is contained in:
squidfunk 2023-06-06 11:48:24 +02:00
parent 1bbc7822d6
commit d2f403495c
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
4 changed files with 15 additions and 8 deletions

View File

@ -240,7 +240,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.b4d07000.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.a51614de.min.js' | url }}"></script>
{% for path in config.extra_javascript %}
{% if path.endswith(".mjs") %}
<script type="module" src="{{ path | url }}"></script>

View File

@ -119,6 +119,10 @@ export function mountPalette(
const meta = h("meta", { name: "theme-color" })
document.head.appendChild(meta)
// Add color scheme meta tag
const scheme = h("meta", { name: "color-scheme" })
document.head.appendChild(scheme)
/* Mount component on subscription */
return defer(() => {
const push$ = new Subject<Palette>()
@ -145,10 +149,13 @@ export function mountPalette(
.pipe(
map(() => {
const header = getComponentElement("header")
const { backgroundColor } = window.getComputedStyle(header)
const style = window.getComputedStyle(header)
// Set color scheme
scheme.content = style.colorScheme
/* Return color in hexadecimal format */
return backgroundColor.match(/\d+/g)!
return style.backgroundColor.match(/\d+/g)!
.map(value => (+value).toString(16).padStart(2, "0"))
.join("")
})