Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Mermaid.js diagram tool in blogs and docs #2167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ unsafe = true

[params]
font_awesome_version = "5.12.0"
mermaid_version = ["9.2.2", "sha384-W/RuUCsZGwf4MwkS0K4JdFzoA0RgiA6foiYzRo68rW5DNPfq+5Dr0uGKY1zecHEA"]
description = "Open 3D Engine (O3DE) is a modular, open source, cross-platform 3D engine built to power anything from AAA games to cinema-quality 3D worlds to high-fidelity simulations. No fees or commercial obligations. Apache 2.0-licensed. Managed by The Linux Foundation."
favicon = "favicon.ico"
repositoryUrl = "https://github.com/o3de/o3de.org"
Expand Down
58 changes: 57 additions & 1 deletion content/smoketest.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,60 @@ $$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \

**Example Output**

$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$

## Embedding Mermaid diagrams

**Example UML Class Diagram**

````
```mermaid
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
```
````

**Example Output**

```mermaid
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
```
4 changes: 4 additions & 0 deletions layouts/_default/_markup/render-codeblock-mermaid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="mermaid">
{{- .Inner | safeHTML }}
</div>
{{ .Page.Store.Set "hasMermaid" true }}
8 changes: 8 additions & 0 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ define "main" }}
{{ $mermaidVersion := site.Params.mermaid_version }}
<div class="container">
<section class="row">
<section class="col col-8">
Expand All @@ -8,6 +9,13 @@ <h1 class="title">{{ .Page.Title | markdownify }}</h1>
{{ . }}
</div>
{{ end }}

{{ if .Page.Store.Get "hasMermaid" }}
<script src="https://cdn.jsdelivr.net/npm/mermaid@{{ index $mermaidVersion 0 }}/dist/mermaid.min.js" integrity="{{ index $mermaidVersion 1 }}" crossorigin="anonymous"></script>
<script>
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}
</section>
</section>
</div>
Expand Down
9 changes: 9 additions & 0 deletions layouts/partials/blog/content.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{{ $mermaidVersion := site.Params.mermaid_version }}
{{ $posts := where site.RegularPages "Section" "blog" }}
<div class="container">
<div class="columns">
<div class="col col-12">
<div class="">
{{ .Content }}
</div>

{{ if .Page.Store.Get "hasMermaid" }}
<script src="https://cdn.jsdelivr.net/npm/mermaid@{{ index $mermaidVersion 0 }}/dist/mermaid.min.js" integrity="{{ index $mermaidVersion 1 }}" crossorigin="anonymous"></script>
<script>
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}

<a class="btn btn-primary back-to-blog" href="/blog">
<span>
Back to blogs
Expand Down
8 changes: 8 additions & 0 deletions layouts/partials/docs/content.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{{ $mermaidVersion := site.Params.mermaid_version }}
{{ with .Content }}
<div class="content">
{{ . }}
</div>
{{ end }}

{{ if .Page.Store.Get "hasMermaid" }}
<script src="https://cdn.jsdelivr.net/npm/mermaid@{{ index $mermaidVersion 0 }}/dist/mermaid.min.js" integrity="{{ index $mermaidVersion 1 }}" crossorigin="anonymous"></script>
<script>
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}