增加对mermaid流程图的支持 (#263)

This commit is contained in:
panoshu 2023-02-12 17:44:30 +08:00 committed by GitHub
parent 1c6ce2dae5
commit d883483ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 5 deletions

View File

@ -79,7 +79,7 @@ search:
field: all # post, page, all field: all # post, page, all
path: /search.json # 搜索文件存放位置 path: /search.json # 搜索文件存放位置
content: true # 是否搜索内容 content: true # 是否搜索内容
######## Comments ######## ######## Comments ########
comments: comments:
@ -127,7 +127,7 @@ comments:
twikoo: twikoo:
js: https://gcore.jsdelivr.net/npm/twikoo@1.6.8/dist/twikoo.all.min.js # 建议锁定版本 js: https://gcore.jsdelivr.net/npm/twikoo@1.6.8/dist/twikoo.all.min.js # 建议锁定版本
envId: https://xxx # vercel函数 envId: https://xxx # vercel函数
# Waline # Waline
# https://waline.js.org/ # https://waline.js.org/
waline: waline:
@ -168,12 +168,12 @@ comments:
# api: # 图床 api 地址 # api: # 图床 api 地址
# token: # 图床验证 # token: # 图床验证
# resp: # 图片地址返回值的字段 # resp: # 图片地址返回值的字段
# Artalk # Artalk
# https://artalk.js.org/ # https://artalk.js.org/
artalk: artalk:
css: https://unpkg.com/artalk@2.4.3/dist/Artalk.css css: https://unpkg.com/artalk@2.4.3/dist/Artalk.css
js: https://unpkg.com/artalk@2.4.3/dist/Artalk.js js: https://unpkg.com/artalk@2.4.3/dist/Artalk.js
server: # 后端服务地址 server: # 后端服务地址
placeholder: '' placeholder: ''
darkMode: auto darkMode: auto
@ -271,7 +271,7 @@ plugins:
weibo: /js/plugins/weibo.js weibo: /js/plugins/weibo.js
marked: https://cdn.bootcdn.net/ajax/libs/marked/4.0.18/marked.min.js marked: https://cdn.bootcdn.net/ajax/libs/marked/4.0.18/marked.min.js
## optional plugins ## ## optional plugins ##
# preload # preload
preload: preload:
@ -338,6 +338,23 @@ plugins:
min_js: <script defer src="https://gcore.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script> min_js: <script defer src="https://gcore.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script>
auto_render_min_js: <script defer src="https://gcore.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"onload="renderMathInElement(document.body);"></script> auto_render_min_js: <script defer src="https://gcore.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"onload="renderMathInElement(document.body);"></script>
# Mermaid - markdwon to flow chart, seq chart, class chart ...
# 需要安装 npm install --save hexo-filter-mermaid-diagrams
# 使用时 需要在Markdown文件开头加入 mermaid: true
# 使用示例:
# ```mermaid
# graph LR
# A(Section A) -->|option 1| B(Section A)
# B -->|option 2| C(Section C)
# ```
mermaid:
enable: false
# js: https://unpkg.com/mermaid@9.0.0/dist/mermaid.min.js
js: https://cdn.jsdelivr.net/npm/mermaid@v9/dist/mermaid.min.js
# Available themes: default | dark | forest | neutral
# 推荐使用 dark 主题 在夜间模式下显示效果更好
theme: dark
style: style:
darkmode: auto # auto / always / false darkmode: auto # auto / always / false
smooth_scroll: true # true / false smooth_scroll: true # true / false

28
layout/mermaid.ejs Executable file
View File

@ -0,0 +1,28 @@
<% if (theme.plugins.mermaid.enable) { %>
<script type="text/javascript" src="<%- theme.plugins.mermaid.js %>"></script>
<script>
var mermaid_config = {
startOnLoad: true,
theme: '<%- theme.plugins.mermaid.theme %>',
logLevel: 3,
themeVariables: {
darkMode: true
},
flowchart: {
useMaxWidth: false,
htmlLabels: true,
curve: 'linear'
},
gantt: {
axisFormat: '%m/%d/%Y'
},
sequence: {
actorMargin: 50
}
}
if (window.mermaid) {
mermaid.initialize(mermaid_config);
}
</script>
<% } %>

View File

@ -22,6 +22,9 @@ if (theme.plugins.heti && theme.plugins.heti.enable) {
<% if (page.mathjax == true){ %> <% if (page.mathjax == true){ %>
<%- partial('mathjax') %> <%- partial('mathjax') %>
<% } %> <% } %>
<% if (page.mermaid == true){ %>
<%- partial('mermaid') %>
<% } %>
<%- partial('_partial/main/navbar/breadcrumb') %> <%- partial('_partial/main/navbar/breadcrumb') %>
<article class='md-text content<%- heti %> <%- post.layout %><%- post.indent ? ' indent' : '' %><%- scrollreveal() %>'> <article class='md-text content<%- heti %> <%- post.layout %><%- post.indent ? ' indent' : '' %><%- scrollreveal() %>'>
<%- layoutTitle() %> <%- layoutTitle() %>

View File

@ -9,6 +9,8 @@ if hexo-config('plugins.scrollreveal.enable')
@import 'scrollreveal' @import 'scrollreveal'
if hexo-config('plugins.fancybox.enable') if hexo-config('plugins.fancybox.enable')
@import 'fancybox' @import 'fancybox'
if hexo-config('plugins.mermaid.enable')
@import 'mermaid'
// //

View File

@ -0,0 +1,10 @@
pre.mermaid {
display: inline-block;
width: 100%;
text-align: center;
}
.mermaid svg {
width: 100%;
display: inline-block;
}