Skip to content

Commit

Permalink
Ensure color-scheme meta tag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Jun 6, 2023
1 parent 1bbc782 commit d2f4034
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion material/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
11 changes: 9 additions & 2 deletions src/assets/javascripts/components/palette/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand All @@ -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("")
})
Expand Down

0 comments on commit d2f4034

Please sign in to comment.