Skip to content

Commit

Permalink
perf: support mermaid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
XPoet committed Oct 9, 2023
1 parent ca88520 commit 74e4aec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
27 changes: 27 additions & 0 deletions layout/_partial/common/mermaid.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%
const mermaidVersion = config?.mermaid?.version || '10.5.0'
let mermaidJs = `//cdn.jsdelivr.net/npm/mermaid@${mermaidVersion}/dist/mermaid.min.js`
const { enable: t_cdn_enable, provider: t_cdn_provider } = theme?.cdn || {}
const { enable: pjax_enable } = theme?.pjax || {}
switch (t_cdn_enable === true && t_cdn_provider) {
case 'jsdelivr':
mermaidJs = `//cdn.jsdelivr.net/npm/mermaid@${mermaidVersion}/dist/mermaid.min.js`
break
case 'unpkg':
mermaidJs = `//unpkg.com/mermaid@${mermaidVersion}/dist/mermaid.min.js`
break
}
%>
<script src="<%= mermaidJs %>"></script>
<% if (pjax_enable === true) { %>
<script data-pjax>
if (window.mermaid) {
mermaid.init()
}
</script>
<% } %>
5 changes: 5 additions & 0 deletions layout/_partial/scripts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<% } %>
</div>
<!-- mermaid -->
<% if (config?.mermaid?.enable === true) { %>
<%- partial('common/mermaid') %>
<% } %>
<!-- pjax -->
<% if (theme?.pjax?.enable === true) { %>
<%- partial('pjax/pjax') %>
Expand Down
6 changes: 6 additions & 0 deletions source/css/common/markdown.styl
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,11 @@
background-color var(--background-color-2)
}
}


.mermaid {
background #f5f5f5 !important
border-radius 0.3rem
}
}

0 comments on commit 74e4aec

Please sign in to comment.