Skip to content

Commit

Permalink
feat: mermaid support
Browse files Browse the repository at this point in the history
  • Loading branch information
chollinger93 committed Dec 27, 2024
1 parent 8e382fa commit 41b99c0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ As well as some additional **features**:
- Added `inlineimg` shortcode to render images (e.g. SVGs) in-line
- Added support for `![](image title="title")` syntax for image titles
- Random, somewhat humorous messages at the end of each post
- Added support for [mermaid](https://mermaid.js.org/) diagrams (*loads via CDN by default, can be set via `mermaidCDN`*)

And some **bugfixes**:
- Modified the CSS to
Expand Down Expand Up @@ -86,7 +87,7 @@ cd into your hugo site's root directory and:

```sh
cd themes
git submodule add https://github.com/chollinger93/ink-free
git submodule add https://github.com/chollinger93/ink-free
```

For more information read the [official setup guide](https://gohugo.io/overview/installing/) of Hugo.
Expand Down
5 changes: 3 additions & 2 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ copyright = "© Copyright notice"
#avatar = "https://image.freepik.com/free-vector/young-man-head-with-beard-avatar-character_24877-36786.jpg"

featherIconsCDN = false
mermaidCDN = "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs"

# Site color - dark/light/auto
mode = "auto"
Expand All @@ -36,7 +37,7 @@ copyright = "© Copyright notice"
wpm = 250

# Stupid footers :)
footers = [
footers = [
"What Tiger King can teach us about x86 Assembly",
"10 Reasons why gcc SHOULD be re-written in JavaScript - You won't believe #8!"
]
Expand Down Expand Up @@ -104,4 +105,4 @@ url = "/index.xml"
[markup.tableOfContents]
endLevel = 3
ordered = true
startLevel = 2
startLevel = 2
18 changes: 15 additions & 3 deletions exampleSite/content/posts/post-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ tags: [markdown]

{{< vimeo id="146022717" >}}

## Instagram


## Mermaid

```mermaid
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts <br/>prevail!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```
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 @@
<pre class="mermaid">
{{- .Inner | htmlEscape | safeHTML }}
</pre>
{{ .Page.Store.Set "hasMermaid" true }}
36 changes: 36 additions & 0 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,39 @@
{{- with .Site.Params.Social -}}
<script>feather.replace()</script>
{{- end -}}

{{ if .Store.Get "hasMermaid" }}
{{ $jsUrl:= default "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs" .Site.Params.mermaidCDN }}
<script type="module">
import mermaid from {{ $jsUrl }};

const getMermaidTheme = () => {
const savedScheme = localStorage.getItem('scheme');
if (savedScheme) {
return savedScheme === 'dark' ? 'dark' : 'default';
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default';
};

mermaid.initialize({
startOnLoad: true,
theme: getMermaidTheme()
});

const applyTheme = () => {
const newTheme = getMermaidTheme();
mermaid.initialize({
startOnLoad: true,
theme: newTheme
});
};

window.addEventListener('storage', (event) => {
if (event.key === 'scheme') {
applyTheme();
}
});

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', applyTheme);
</script>
{{ end }}

0 comments on commit 41b99c0

Please sign in to comment.