Hugo教程
目录
基本概念
-
template,在
layouts/目录中的文件即为html模板文件,可以通过{{}}模板动作动态生成内容 -
archetype,在
archetype目录中的markdown模板文件,创建新内容时以它作为文章模板 -
Context,即为传入template的数据,在template中以
{{.}}表示,context可能是一个单个值,可能是个对象。比如page template接收一个Page对象。Page对象上有许多方法,比如{{.Title}}获取当前页面的title。当使用range或者withblocks的时候,context会改变,可以使用{{$.Title}}访问template context,而不是当前context -
action,在
{{}}中可访问context或者调用函数,或者使用if1 2 3 4{{ $convertToLower := true }} {{ if $convertToLower }} <h2>{{ strings.ToLower .Title }}</h2> {{ end }} -
function,可以在action中使用函数,常用的函数会有alias,比如
{{math.Add 1 2}}可写成{{add 1 2}}。 参数用空格隔开,有些函数没有参数,写成{{func}}。
netlify部署
-
设置环境变量为
HUGO_VERSION,值为本地hugo的版本号(通过hugo version查看),比如0.160.1 -
Build command设置为
1git submodule update --init --recursive --depth 1 && hugo -
publish directory设置为
public
文章作者 surwall
上次更新 2026-05-01 19:21:24