我們可使用 | operator 將多個 Function 組合起來實現 Function Pipeline。
Version
Hugo 0.91
Page

my blog的首字母大寫後成為My Blog- Markdown 中的
**被轉成<strong>
Page Variable
content/_index.md
---
title: my **blog**
---
title:定義 Page variable
Pipe
layouts/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="alpine.js" defer></script>
<link rel="stylesheet" href="output.css" />
</head>
<body>
<h1 class="text-4xl text-red-500">{{ .Title | humanize | markdownify }}</h1>
</body>
</html>
Line 10
<h1 class="text-4xl text-red-500">{{ .Title | humanize | markdownify }}</h1>
humanize:將單字的第一個字大寫markdownify:將 markdown 轉成 HTML|:以 Function Pipeline 串連humanize()與markdownify()
Conclusion
- 當在 Go template 使用多個 function 時,
|寫法的可讀性更高