Skip to content

Commit

Permalink
Add configuration to enable mermaid
Browse files Browse the repository at this point in the history
This ensures that the extra resources are only loaded if the author wishes to use mermaid diagrams.

Had to use reveal dependencies to ensure the first load works although the dependency mechanism is deprecated in later versions. Loading the dependencies with `async: true` didn’t work.
  • Loading branch information
mrmanc committed Sep 5, 2022
1 parent 9118701 commit f7544ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ reveal_options:

# Additional reveal.js dependencies
reveal_dependencies:
- "{ src: 'js/mermaid/mermaid.js' },"

# Reveal.js subdirectory
reveal_path: reveal.js/

# mermaid.js diagram integration
mermaid_diagrams: true

# Exclude directories and/or files from the conversion
exclude:
- Gemfile*
Expand Down
10 changes: 6 additions & 4 deletions _layouts/reveal.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
<link rel="stylesheet" href="{{ css_file }}">
{% endfor %}
{% endif %}
{% if site.mermaid_diagrams %}
<link rel="stylesheet" href="{{ 'css/mermaid.css' | relative_url }}">

{% endif %}
<!-- For syntax highlighting -->
{% if site.highlight_style_sheet %}
{% assign highlight_style_sheet = site.highlight_style_sheet %}
Expand Down Expand Up @@ -85,9 +86,6 @@
</div>

</div>

<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js"></script>

<script src="{{ site.reveal_path }}lib/js/head.min.js"></script>
<script src="{{ site.reveal_path }}js/reveal.js"></script>

Expand Down Expand Up @@ -123,6 +121,10 @@
{ src: '{{ site.reveal_path }}plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '{{ site.reveal_path }}plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: '{{ site.reveal_path }}plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{% if site.mermaid_diagrams %}
{ src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js'},
{ src: '{{ 'js/mermaid/mermaid.js' | relative_url }}'},
{% endif %}
{% if site.reveal_notes_server %}
{ src: '{{ site.reveal_path }}socket.io/socket.io.js', async: true },
{ src: '{{ site.reveal_path }}plugin/notes-server/client.js', async: true }
Expand Down

0 comments on commit f7544ac

Please sign in to comment.