<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mermaid &#8211; 编程技术记录</title>
	<atom:link href="https://blog.z6z8.cn/tag/mermaid/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.z6z8.cn</link>
	<description>世界你好!</description>
	<lastBuildDate>Mon, 01 Dec 2025 10:26:16 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>在hugo里集成mermaid图支持</title>
		<link>https://blog.z6z8.cn/2025/12/01/%e5%9c%a8hugo%e9%87%8c%e9%9b%86%e6%88%90mermaid%e5%9b%be%e6%94%af%e6%8c%81/</link>
					<comments>https://blog.z6z8.cn/2025/12/01/%e5%9c%a8hugo%e9%87%8c%e9%9b%86%e6%88%90mermaid%e5%9b%be%e6%94%af%e6%8c%81/#respond</comments>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Mon, 01 Dec 2025 09:42:07 +0000</pubDate>
				<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[hugo]]></category>
		<category><![CDATA[mermaid]]></category>
		<guid isPermaLink="false">https://blog.z6z8.cn/?p=1514</guid>

					<description><![CDATA[本文环境： hugo v0.152.2+extended+withdeploy darwin/amd64 Bu [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>本文环境：<br />
hugo v0.152.2+extended+withdeploy darwin/amd64 BuildDate=2025-10-24T15:31:49Z VendorInfo=Homebrew</p>
<p>一般使用了hugo主题的话，默认是集成了mermaid图。<br />
若不使用hugo主题，那么就需要自己手动集成了。<br />
步骤如下：</p>
<h2>创建 layouts/_markup/render-codeblock-mermaid.html</h2>
<p>负责开启一个mermaid图的html区块，内容如下：</p>
<pre><code class="language-html">&lt;pre class=&quot;mermaid&quot;&gt;
    {{- .Inner | safeHTML }}
  &lt;/pre&gt;
  {{ .Page.Store.Set &quot;hasMermaid&quot; true }}</code></pre>
<h2>修改 layouts/_default/baseof.html</h2>
<p>如果没有该文件就创建一个。默认情况下，所有html页面的主体结构和内容由这个文件渲染。和mermaid图相关的内容如下:</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;zh-CN&quot;&gt;

&lt;body&gt;
   ......
   ......
   ......

   &lt;!-- 必须放到最后在 （.Content 之下），因为这渲染钩子直到执行 .Content 之后才会被处理），否则.Page.Store.Get &quot;hasMermaid&quot;永远为false --&gt;
       {{ if .Page.Store.Get &quot;hasMermaid&quot; }}
    &lt;!-- 只有文章里写了 mermaid 才加载下面这些资源，节省性能 --&gt;
        &lt;script type=&quot;module&quot;&gt;
            import mermaid from &#039;https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs&#039;;
            mermaid.initialize({ startOnLoad: true });
        &lt;/script&gt;
    {{ end }}
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<h2>添加一个mermaid图看看效果</h2>
<p>在网站的任意一个markdown文件里添加样例，看下效果</p>
<pre><code>```mermaid
flowchart LR
%% 左右布局（TD=上下，LR=左右，TB=上下，BT=下上）
    Start[开始] --&gt; Stop[结束]
    A[矩形节点] --&gt; B(圆角矩形)
    C{菱形判断} --&gt;|是| D[操作1]
    C --&gt;|否| E[操作2]</code></pre>
<pre><code></code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.z6z8.cn/2025/12/01/%e5%9c%a8hugo%e9%87%8c%e9%9b%86%e6%88%90mermaid%e5%9b%be%e6%94%af%e6%8c%81/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
