基本概念

  1. template,在layouts/目录中的文件即为html模板文件,可以通过{{}}模板动作动态生成内容

  2. archetype,在archetype目录中的markdown模板文件,创建新内容时以它作为文章模板

  3. Context,即为传入template的数据,在template中以{{.}}表示,context可能是一个单个值,可能是个对象。比如page template接收一个Page对象。Page对象上有许多方法,比如{{.Title}}获取当前页面的title。当使用range或者withblocks的时候,context会改变,可以使用{{$.Title}}访问template context,而不是当前context

  4. action,在{{}}中可访问context或者调用函数,或者使用if

    1
    2
    3
    4
    
    {{ $convertToLower := true }}
    {{ if $convertToLower }}
      <h2>{{ strings.ToLower .Title }}</h2>
    {{ end }}
    
  5. function,可以在action中使用函数,常用的函数会有alias,比如{{math.Add 1 2}}可写成{{add 1 2}}。 参数用空格隔开,有些函数没有参数,写成{{func}}

netlify部署

  1. 设置环境变量为HUGO_VERSION,值为本地hugo的版本号(通过hugo version查看),比如0.160.1

  2. Build command设置为

    1
    
    git submodule update --init --recursive --depth 1 && hugo
    
  3. publish directory设置为public