From 84733456bdf62d1b0085c47c34b505cff9f2c3db Mon Sep 17 00:00:00 2001 From: PCloud Date: Mon, 23 Sep 2024 09:55:59 +0100 Subject: [PATCH] feat: add support for maths passthrough render hook --- exampleSite/config/_default/markup.toml | 2 +- layouts/_default/_markup/render-passthrough.html | 8 ++++++++ layouts/partials/assets.html | 4 ++++ layouts/partials/init.html | 14 +------------- 4 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 layouts/_default/_markup/render-passthrough.html diff --git a/exampleSite/config/_default/markup.toml b/exampleSite/config/_default/markup.toml index cc46377b4..584756910 100644 --- a/exampleSite/config/_default/markup.toml +++ b/exampleSite/config/_default/markup.toml @@ -27,7 +27,7 @@ # 是否在文档中直接使用 HTML 标签 unsafe = true [goldmark.extensions.passthrough] - enable = true + enable = false [goldmark.extensions.passthrough.delimiters] block = [['\[', '\]'], ['$$', '$$']] inline = [['\(', '\)']] diff --git a/layouts/_default/_markup/render-passthrough.html b/layouts/_default/_markup/render-passthrough.html new file mode 100644 index 000000000..ab46d3f23 --- /dev/null +++ b/layouts/_default/_markup/render-passthrough.html @@ -0,0 +1,8 @@ +{{- .Page.Scratch.SetInMap "this" "math" true -}} +{{- if eq .Type "block" -}} + {{- $opts := dict "displayMode" true "output" "html" -}} + {{- transform.ToMath .Inner $opts -}} +{{- else -}} + {{- $opts := dict "displayMode" false "output" "html" -}} + {{- transform.ToMath .Inner $opts -}} +{{- end -}} \ No newline at end of file diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index 2c7819fc2..cc47e5edc 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -80,6 +80,10 @@ {{- end -}} {{- /* KaTeX */ -}} +{{- if (.Scratch.Get "this").math -}} + {{- $source := $cdn.katexCSS | default "lib/katex/katex.min.css" -}} + {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} +{{- end -}} {{- $math := $params.math -}} {{- if eq $math true -}} {{- $math = .Site.Params.page.math | default dict -}} diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 14fadcca7..ca519c4f5 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -1,17 +1,5 @@ {{- .Scratch.Set "version" "0.4.0" -}} -{{- /* DoIt theme version detection */ -}} -{{/* {{- $VERSION := "0.3.X" -}} -{{- if eq .Site .Sites.First -}} - {{- if not .Site.Params.version -}} - {{- errorf "Configuration Error 配置文件错误\n\nYou haven't configured the DoIt version param correctly yet. See https://hugodoit.pages.dev/theme-documentation-basics/#basic-configuration\n你还没有正确配置 DoIt 的版本参数. 参考 https://hugodoit.pages.dev/zh-cn/theme-documentation-basics/#basic-configuration\n\n" -}} - {{- else if ne .Site.Params.version $VERSION -}} - {{- errorf (printf "Compatibility Error 兼容性错误\n\n%v -> %v:\nYou have an incompatible update. See https://github.com/HEIGE-PCloud/DoIt/releases\n你进行了一次不兼容的更新. 参考 https://github.com/HEIGE-PCloud/DoIt/releases\n\n" .Site.Params.version $VERSION) -}} - {{- end -}} -{{- end -}} */}} -{{/* temporarily disabling the version check, 0.3.X does not really contain a breaking change */}} -{{/* TODO: properly restore DoIt using semiVer */}} - {{- /* Check Hugo version */ -}} {{- $OLDEST_SUPPORTED_HUGO_VERSION := "0.134.0" -}} {{- if lt hugo.Version $OLDEST_SUPPORTED_HUGO_VERSION -}} @@ -49,7 +37,7 @@ {{- else if eq .Params.comment false -}} {{- .Scratch.Set "comment" dict -}} {{- end -}} -{{- else if eq .Site .Sites.First -}} +{{- else if eq .Site .Sites.Default -}} {{- warnf "\n\nCurrent environment is \"development\". The \"comment system\", \"PWA\", \"CDN\" and \"fingerprint\" will be disabled.\n当前运行环境是 \"development\". \"评论系统\", \"PWA\", \"CDN\" 和 \"fingerprint\" 不会启用.\n\n" -}} {{- end -}}