* Add support for Mermaid diagrams in markdown content
This commit introduces native Mermaid diagram rendering to the theme.
Following Hugo’s official documentation, a new custom code block renderer
(`render-codeblock-mermaid.html`) was added under `layouts/_default/` to
detect Mermaid code blocks and inject the necessary script flag into the
page context.
Additionally, the `baseof.html` template now conditionally includes the
Mermaid JS module from the CDN when a page contains a Mermaid diagram:
{{ if .Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true, theme: 'neutral' });
</script>
{{ end }}
This enables rendering of fenced code blocks using the `mermaid` language
in markdown files without requiring any external preprocessing.
* Create article/components/mermaid and fix script version
---------
Co-authored-by: Jimmy <jimmy@cai.im>
48 lines
1.5 KiB
HTML
48 lines
1.5 KiB
HTML
{{ define "body-class" }}
|
|
article-page
|
|
{{/*
|
|
Enable the right sidebar if
|
|
- Widget different from 'TOC' is enabled
|
|
- TOC is enabled and not empty
|
|
*/}}
|
|
{{- $HasWidgetNotTOC := false -}}
|
|
{{- $TOCWidgetEnabled := false -}}
|
|
{{- range .Site.Params.widgets.page -}}
|
|
{{- if ne .type "toc" -}}
|
|
{{ $HasWidgetNotTOC = true -}}
|
|
{{- else -}}
|
|
{{ $TOCWidgetEnabled = true -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $TOCManuallyDisabled := eq .Params.toc false -}}
|
|
{{- $TOCEnabled := and (not $TOCManuallyDisabled) $TOCWidgetEnabled -}}
|
|
{{- $hasTOC := ge (len .TableOfContents) 100 -}}
|
|
{{- .Scratch.Set "TOCEnabled" (and $TOCEnabled $hasTOC) -}}
|
|
|
|
{{- .Scratch.Set "hasWidget" (or $HasWidgetNotTOC (and $TOCEnabled $hasTOC)) -}}
|
|
{{ end }}
|
|
|
|
{{ define "main" }}
|
|
{{ partial "article/article.html" . }}
|
|
|
|
{{ if .Params.links }}
|
|
{{ partial "article/components/links" . }}
|
|
{{ end }}
|
|
|
|
{{ partial "article/components/related-content" . }}
|
|
|
|
{{ if not (eq .Params.comments false) }}
|
|
{{ partial "comments/include" . }}
|
|
{{ end }}
|
|
|
|
{{ partialCached "footer/footer" . }}
|
|
|
|
{{ partialCached "article/components/photoswipe" . }}
|
|
{{ partialCached "article/components/mermaid" . }}
|
|
{{ end }}
|
|
|
|
{{ define "right-sidebar" }}
|
|
{{ if .Scratch.Get "hasWidget" }}{{ partial "sidebar/right.html" (dict "Context" . "Scope" "page") }}{{ end}}
|
|
{{ end }}
|