From fde7e1cf384f098550d8dcf5ff3a3f855fc9f7f5 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Mon, 8 Sep 2025 16:28:08 +0800 Subject: [PATCH] fix: Params configurations case insensitive for mathjax and watermark (#633) * refactor: set watermark config in template, change the default content to author name or site title * fix: case insensitive for mathjax options param * chore: fix typo --- assets/js/lib/mathjax.js | 1 - assets/js/theme.js | 17 ++++------------- hugo.toml | 21 ++++++++++++++++++++- layouts/_partials/assets.html | 30 ++++++++++++++++++++++++++---- 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/assets/js/lib/mathjax.js b/assets/js/lib/mathjax.js index a35c9efb..967d57be 100644 --- a/assets/js/lib/mathjax.js +++ b/assets/js/lib/mathjax.js @@ -36,7 +36,6 @@ window.MathJax = { }, }, options: { - ignoreHtmlClass: 'comment', processHtmlClass: 'content', ...params.options, } diff --git a/assets/js/theme.js b/assets/js/theme.js index f6551b7e..20c8cecc 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -1053,19 +1053,10 @@ class FixIt { } initWatermark() { - this.config.watermark?.enable && - new Watermark({ - content: this.config.watermark.content || `${document.querySelector('footer .fixit-icon')?.outerHTML ?? ''} FixIt Theme`, - appendTo: '.widgets', - opacity: this.config.watermark.opacity, - width: this.config.watermark.width, - height: this.config.watermark.height, - rowSpacing: this.config.watermark.rowspacing, - colSpacing: this.config.watermark.colspacing, - rotate: this.config.watermark.rotate, - fontSize: this.config.watermark.fontsize, - fontFamily: this.config.watermark.fontfamily - }); + if (!this.config.watermark?.enable) { + return; + } + new Watermark(this.config.watermark); } initPangu() { diff --git a/hugo.toml b/hugo.toml index 35a27c78..4d464116 100644 --- a/hugo.toml +++ b/hugo.toml @@ -1149,7 +1149,26 @@ mainSections = [] # more loader config e.g source, dependencies, provides etc. [params.page.math.mathjax.options] enableMenu = true - # more options config e.g. skipHtmlTags, ignoreHtmlClass etc. + # HTML tags that won't be searched for math + skipHtmlTags = [ + "script", + "noscript", + "style", + "textarea", + "pre", + "code", + "math", + "select", + "option", + "mjx-container" + ] + # class that marks tags not to search + ignoreHtmlClass = "mathjax_ignore" + # HTML tags that can appear within math + [params.page.math.mathjax.options.includeHtmlTags] + # "#comment" = "" + # br = "\n" + # wbr = "" # Code wrapper config [params.page.code] # FixIt 0.3.9 | NEW whether to enable the code wrapper diff --git a/layouts/_partials/assets.html b/layouts/_partials/assets.html index 20e7e3a0..458d79a6 100644 --- a/layouts/_partials/assets.html +++ b/layouts/_partials/assets.html @@ -4,6 +4,7 @@ {{- $fingerprint := .Site.Store.Get "fingerprint" -}} {{- $config := (.Store.Get "this").config -}} {{- $config = dict "version" (hugo.Store.Get "version") | merge $config -}} +{{- $author := partial "function/get-author-map.html" .Params.author -}} {{- /* Search */ -}} {{- if .Site.Params.search | and .Site.Params.search.enable -}} @@ -109,8 +110,20 @@ {{- $mathjax := $math.mathjax -}} {{- $source := "js/lib/mathjax.js" -}} {{- $options := dict "targetPath" "js/lib/mathjax.min.js" "minify" hugo.IsProduction -}} - {{- $mathjaxOpts := $mathjax.options | default dict -}} - {{- $mathjaxOpts = dict "enableMenu" $mathjaxOpts.enablemenu | merge $mathjaxOpts -}} + {{- $mathjaxOptsConfig := $mathjax.options | default dict -}} + {{- $mathjaxOpts := dict -}} + {{- with $mathjaxOptsConfig.enableMenu -}} + {{- $mathjaxOpts = dict "enableMenu" . | merge $mathjaxOpts -}} + {{- end -}} + {{- with $mathjaxOptsConfig.ignoreHtmlClass -}} + {{- $mathjaxOpts = dict "ignoreHtmlClass" . | merge $mathjaxOpts -}} + {{- end -}} + {{- with $mathjaxOptsConfig.skipHtmlTags -}} + {{- $mathjaxOpts = dict "skipHtmlTags" . | merge $mathjaxOpts -}} + {{- end -}} + {{- with $mathjaxOptsConfig.includeHtmlTags -}} + {{- $mathjaxOpts = dict "includeHtmlTags" . | merge $mathjaxOpts -}} + {{- end -}} {{- $params := dict "cdn" $mathjax.cdn "tex" ($mathjax.tex | default dict) @@ -191,8 +204,17 @@ {{- if eq .Site.Params.watermark.enable true -}} {{- $source := $cdn.cellWatermarkJS | default "lib/cell-watermark/watermark.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}} - {{- /* Hugo bug: case insensitive for `.Site.Params` */ -}} - {{- $config = dict "watermark" .Site.Params.watermark | merge $config -}} + {{- $watermarkConfig := .Site.Params.watermark | default dict -}} + {{- $watermarkConfig = dict + "appendTo" ".widgets" + "content" ($watermarkConfig.content | default $author.name | default .Site.Title) + "rowSpacing" $watermarkConfig.rowSpacing + "colSpacing" $watermarkConfig.colSpacing + "fontSize" $watermarkConfig.fontSize + "fontFamily" $watermarkConfig.fontFamily + | merge $watermarkConfig + -}} + {{- $config = dict "watermark" $watermarkConfig | merge $config -}} {{- end -}} {{- /* Content Decryption */ -}}