Merge pull request #2814 from ZhenShuo2021/logo-alt
✨ Feat: logo alt and remove logo JS
This commit is contained in:
@@ -96,7 +96,6 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var updateMeta = () => {
|
||||
var elem, style;
|
||||
elem = document.querySelector('body');
|
||||
@@ -104,33 +103,6 @@ var updateMeta = () => {
|
||||
document.querySelector('meta[name="theme-color"]').setAttribute('content', style.backgroundColor);
|
||||
}
|
||||
|
||||
{{ if and (.Site.Params.Logo) (.Site.Params.SecondaryLogo) }}
|
||||
{{ $primaryLogo := resources.Get .Site.Params.Logo }}
|
||||
{{ $secondaryLogo := resources.Get .Site.Params.SecondaryLogo }}
|
||||
{{ if and ($primaryLogo) ($secondaryLogo) }}
|
||||
var updateLogo = (targetAppearance) => {
|
||||
var imgElems = document.querySelectorAll("img.logo");
|
||||
var logoContainers = document.querySelectorAll("span.logo");
|
||||
|
||||
targetLogoPath =
|
||||
targetAppearance == "{{ .Site.Params.DefaultAppearance }}" ?
|
||||
"{{ $primaryLogo.RelPermalink }}" : "{{ $secondaryLogo.RelPermalink }}"
|
||||
for (const elem of imgElems) {
|
||||
elem.setAttribute("src", targetLogoPath)
|
||||
}
|
||||
|
||||
{{ if eq $primaryLogo.MediaType.SubType "svg" }}
|
||||
targetContent =
|
||||
targetAppearance == "{{ .Site.Params.DefaultAppearance }}" ?
|
||||
`{{ $primaryLogo.Content | safeHTML }}` : `{{ $secondaryLogo.Content | safeHTML }}`
|
||||
for (const container of logoContainers) {
|
||||
container.innerHTML = targetContent;
|
||||
}
|
||||
{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
|
||||
var getTargetAppearance = () => {
|
||||
return document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user