🐛 Fix: attribute media not allowed on element meta in [name=theme-color]

🐛 Fix: support smooth migration from LoveIt to FixIt (#174 #182)
This commit is contained in:
Cell
2022-08-27 01:43:54 +08:00
parent 913a82fe18
commit d27a42dab2
6 changed files with 24 additions and 9 deletions
+2
View File
@@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.
- :bug: Fix: add function doc2unix to unify new lines symbol between Windows and Unix/Mac OS
- :bug: Fix: author display error in post and markdown file
- :bug: Fix: use data attributes or class replace for custom attributes
- :bug: Fix: attribute `media` not allowed on element meta in `[name=theme-color]`
- :bug: Fix: support smooth migration from LoveIt to FixIt ([#174](https://github.com/hugo-fixit/FixIt/discussions/174) [#182](https://github.com/hugo-fixit/FixIt/issues/182))
- :art: Style: change the default icons of some social links
- :globe_with_meridians: Docs(i18n): update pt-br, de in i18n
- :mag: Perf(SEO): enhance SEO performance
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
Submodule docs updated: 321912688f...4ea2b1b659
+6 -6
View File
@@ -23,12 +23,12 @@
<meta name="application-name" content="{{ .Site.Params.app.title | default .Site.Title }}">
<meta name="apple-mobile-web-app-title" content="{{ .Site.Params.app.title | default .Site.Title }}">
{{- with .Site.Params.app.themeColor.light -}}
<meta name="theme-color" media="(prefers-color-scheme: light)" content="{{ . }}">
{{- end -}}
{{- with .Site.Params.app.themeColor.dark -}}
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="{{ . }}">
{{- with .Site.Params.app.themeColor -}}
{{- $color := . -}}
{{- if ne (len $color) 2 -}}
{{- $color = dict "light" . "dark" . -}}
{{- end -}}
<meta name="theme-color" data-light="{{ $color.light }}" data-dark="{{ $color.dark }}" content="{{ $color.light }}">
{{- end -}}
{{- with .Site.Params.app.tileColor -}}
+13
View File
@@ -62,6 +62,18 @@ class FixIt {
window.objectFitImages && objectFitImages();
}
initThemeColor() {
const $meta = document.querySelector('[name="theme-color"]');
if (!$meta) {
return;
}
this._themeColorOnSwitchTheme = this._themeColorOnSwitchTheme || (() => {
$meta.content = this.isDark ? $meta.dataset.dark : $meta.dataset.light;
});
this.switchThemeEventSet.add(this._themeColorOnSwitchTheme);
this._themeColorOnSwitchTheme();
}
initSVGIcon() {
this.util.forEach(document.querySelectorAll('[data-svg-src]'), ($icon) => {
fetch($icon.getAttribute('data-svg-src'))
@@ -1075,6 +1087,7 @@ class FixIt {
this.initMapbox();
this.initPangu();
}
this.initThemeColor();
this.initSVGIcon();
this.initMenu();
this.initSwitchTheme();