From d511a6f520bcc2ffab10ce009239904774ed6bb0 Mon Sep 17 00:00:00 2001
From: Jeffrey Forman <58740+jforman@users.noreply.github.com>
Date: Sat, 21 May 2022 09:47:30 +0000
Subject: [PATCH] feat: added mermaid support for displaying diagrams (#359)

---
 layouts/_default/single.html                           |    6 ++++++
 layouts/partials/mermaid.html                          |    7 +++++++
 layouts/_default/_markup/render-codeblock-mermaid.html |    4 ++++
 exampleSite/config/_default/params.toml                |    3 +++
 README.md                                              |    1 +
 5 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md
index abed1c6..2811769 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,7 @@
 - Custom JavaScript and CSS (optional)
 - Compliant to strict CSP
 - Post Series
+- Mermaid diagram support (optional)
 
 ## Preview the Example Site
 
diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml
index fe21e86..3f7d450 100644
--- a/exampleSite/config/_default/params.toml
+++ b/exampleSite/config/_default/params.toml
@@ -73,3 +73,6 @@
 icon = "fas fa-envelope"
 title = "e-mail"
 url = "mailto:mail@example.com"
+
+[mermaid]
+# enable = true
\ No newline at end of file
diff --git a/layouts/_default/_markup/render-codeblock-mermaid.html b/layouts/_default/_markup/render-codeblock-mermaid.html
new file mode 100644
index 0000000..5964155
--- /dev/null
+++ b/layouts/_default/_markup/render-codeblock-mermaid.html
@@ -0,0 +1,4 @@
+<div class="mermaid">
+  {{- .Inner | safeHTML }}
+</div>
+{{ .Page.Store.Set "hasMermaid" true }}
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index fbd73e8..f9ddd5a 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -68,6 +68,12 @@
 
 
       {{- end -}}
+
+      {{- if (eq .Site.Params.mermaid.enable true) -}}
+        {{- partial "mermaid.html" . -}}
+
+
+      {{- end -}}
     </div>
     <div class="post__footer">
       {{ with .Page.Params.Categories }}
diff --git a/layouts/partials/mermaid.html b/layouts/partials/mermaid.html
new file mode 100644
index 0000000..bcfd35d
--- /dev/null
+++ b/layouts/partials/mermaid.html
@@ -0,0 +1,7 @@
+{{ if .Page.Store.Get "hasMermaid" }}
+  <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
+  <script>
+    mermaid.initialize({ startOnLoad: true });
+  </script>
+
+{{ end }}

--
Gitblit v1.10.0