Key
Syntax
RESOURCE.Key
Returns
string
例如,考虑此网站配置:
        hugo.
      
      
       
      
       
      
       
  baseURL: https://example.org/docs/
baseURL = 'https://example.org/docs/'
{
   "baseURL": "https://example.org/docs/"
}
以及此模板:
  {{ with resources.Get "images/a.jpg" }}
    {{ with resources.Copy "foo/bar/b.jpg" . }}
      {{ .Key }} → foo/bar/b.jpg
      {{ .Name  }} → images/a.jpg
      {{ .Title }} → images/a.jpg
      {{ .RelPermalink }} → /docs/foo/bar/b.jpg
    {{ end }}
  {{ end }}
我们使用 resources.Copy 函数更改了发布路径。Key 方法返回更新后的路径,但请注意它与 RelPermalink 方法返回的值不同。RelPermalink 值包括在网站配置的 baseURL 中的子目录段。
Key 方法在需要获取资源的发布路径但不发布资源时非常有用。与 Permalink、RelPermalink 或 Publish 方法不同,调用 Key 不会发布资源。