From 4a0b13533181d9637fc9a05263ed0f130090828e Mon Sep 17 00:00:00 2001 From: morethan987 <2404385626@qq.com> Date: Sat, 4 Jan 2025 11:33:23 +0800 Subject: [PATCH] support the day/night mod change for SVG logo Relevant issue: #1900 I add some code to support the day/night mod change for SVG logo. It's based on the issue: #676 --- assets/js/appearance.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/assets/js/appearance.js b/assets/js/appearance.js index 1da4b69f..f29e8f4c 100644 --- a/assets/js/appearance.js +++ b/assets/js/appearance.js @@ -76,14 +76,24 @@ var updateMeta = () => { {{ $secondaryLogo := resources.Get .Site.Params.SecondaryLogo }} {{ if and ($primaryLogo) ($secondaryLogo) }} var updateLogo = (targetAppearance) => { - var elems; - elems = document.querySelectorAll("img.logo") + 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 elems) { + 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 }}