Heading link example ¶
目录 ¶
简介 ¶
本例为Hugo
自定义Heading
模板,仓库在
https://github.com/huzhenghui/Hugo-Bootstrap-Templates
效果参见
https://huzhenghui.github.io/Hugo-Bootstrap-Templates/posts/render/heading/example/
本文发表在
https://blog.csdn.net/hu_zhenghui/article/details/128727127
相关文件 ¶
./
├── content/
│ └── posts/
│ └── render/
│ └── heading/
│ └── example.md
└── layouts/
└── render-heading-example/
└── _markup/
└── render-heading.html
内容 ¶
/content/posts/render/heading/example.md
¶
Since v0.3
在front matter
中设置type
属性
---
title: Heading link example
date: 2023-01-18
publishdate: 2023-01-18
type: render-heading-example
---
type
属性值为render-heading-example
,表示优先使用/layouts/render-heading-example/
中的模板,因此渲染时,在渲染Markdown
的标题时,将使用
/layouts/render-heading-example/_markup/render-heading.html
效果为
<h1 id="heading-link-example">
Heading link example
<a href="#heading-link-example">¶</a>
</h1>
模板 ¶
/layouts/render-heading-example/_markup/render-heading.html
¶
自定义Heading
链接模板,位置在https://github.com/huzhenghui/Hugo-Bootstrap-Templates/blob/master/layouts/render-heading-example/_markup/render-heading.html
Since v0.3
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
{{ .Text | safeHTML }}
<a href="#{{ .Anchor | safeURL }}">¶</a>
</h{{ .Level }}>