Skip to content

Commit

Permalink
performance: use hugo render hook for Mermaid
Browse files Browse the repository at this point in the history
This switches Mermaid to use hugo's Markdown
render hooks [1] instead of manipulating the string at runtime, which
should improve performance by a bit.

[1]: https://gohugo.io/templates/render-hooks/#render-hooks-for-code-blocks

Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
  • Loading branch information
stephanlachnit committed Apr 26, 2022
1 parent f97f4f8 commit 34307e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions assets/js/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
{{ if .enable }}
(function($) {
var needMermaid = false;
$('.language-mermaid').parent().replaceWith(function() {
if ($('.mermaid').length > 0) {
needMermaid = true;
return $('<pre class="mermaid">').text($(this).text());
});
};

if (!needMermaid) {
mermaid.initialize({startOnLoad: false});
Expand Down
3 changes: 3 additions & 0 deletions layouts/_default/_markup/render-codeblock-mermaid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="mermaid">
{{- .Inner | safeHTML }}
</div>

0 comments on commit 34307e7

Please sign in to comment.