From 5a233e738466464493b4ba516a4e05d39edd0c2f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 20 Jul 2024 17:24:21 +0100 Subject: [PATCH] layouts: add Mermaid support Similar to Graphviz and TikZ support. --- content/posts/2020-07-14-hello-world/index.md | 14 ++++++++++++++ layouts/partials/head-extra.html | 7 +++++++ layouts/shortcodes/mermaid.html | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 layouts/shortcodes/mermaid.html diff --git a/content/posts/2020-07-14-hello-world/index.md b/content/posts/2020-07-14-hello-world/index.md index 9eb06e8..d430add 100644 --- a/content/posts/2020-07-14-hello-world/index.md +++ b/content/posts/2020-07-14-hello-world/index.md @@ -9,6 +9,7 @@ categories: favorite: false tikz: true graphviz: true +mermaid: true --- ## Test post please ignore @@ -51,6 +52,19 @@ echo hello world | cut -d' ' -f 1 } {{% /graphviz %}} +### Mermaid support + +{{% mermaid %}} + graph TD + A[Enter Chart Definition] --> B(Preview) + B --> C{decide} + C --> D[Keep] + C --> E[Edit Definition] + E --> B + D --> F[Save Image and Code] + F --> B +{{% /graphviz %}} + ### Spoilers {{% spoiler "Don't open me" %}} diff --git a/layouts/partials/head-extra.html b/layouts/partials/head-extra.html index f0a049d..dc97efa 100644 --- a/layouts/partials/head-extra.html +++ b/layouts/partials/head-extra.html @@ -20,6 +20,13 @@ })(); {{ end }} + +{{ if (.Params.mermaid) }} + +{{ end }} {{ with .OutputFormats.Get "atom" -}} {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} {{ end -}} diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html new file mode 100644 index 0000000..80cf0a5 --- /dev/null +++ b/layouts/shortcodes/mermaid.html @@ -0,0 +1,16 @@ +
+    {{ with .Get "file" }}
+        {{ if eq (. | printf "%.1s") "/" }}
+            {{/* Absolute path are from root of site. */}}
+            {{ $.Scratch.Set "filepath" . }}
+        {{ else }}
+            {{/* Relative paths are from page directory. */}}
+            {{ $.Scratch.Set "filepath" $.Page.File.Dir }}
+            {{ $.Scratch.Add "filepath" . }}
+        {{ end }}
+
+        {{ $.Scratch.Get "filepath" | readFile }}
+    {{ else }}
+        {{.Inner}}
+    {{ end }}
+