"featuredpath" 雨果主题

Hugo Theme with "featuredpath"

我正在试验 hugo 和 this theme。从 repo 中的示例站点我可以看到,帖子特色图片的配置方式如下:

featured = "pic.jpg"
featuredalt = "Pic 2"
featuredpath = "date"

这需要我将 pic.jpg 放在 static/img/YEAR/MONTH 中。 有人可以解释一下,这条路径是如何从 featuredpath = "date" 组装而来的吗?还有其他选择吗?也许相对于 source.md 文件?模板魔术发生了 here,但 date 没有包含任何内容。

你走在正确的轨道上。您注意到涉及 layouts/post/featured.html。但请注意这一行:

{{ partial "img-path" . }}

这意味着此处插入了名为 img-path 的部分。因此,我们将跳到它。如果您查看 /layouts/partials/img-path.html,您会在第 7 行看到这条评论:

 if path is date then it will format the directory to year/date i.e. 2006/01

然后您会看到第 18-24 行,它们创建了以日期为中心的图像路径:

{{ $.Scratch.Set "path" "/img/" }}
{{ if eq $structType "shortcode" }}
  {{ $.Scratch.Add "path" (.Page.Date.Format "2006/01") }}
{{ else }}
  {{ $.Scratch.Add "path" (.Date.Format "2006/01") }}
{{ end }}

在一个有点相关的说明中,我发现 Hugo forums 对于获得对此类问题的快速反馈很有价值。

其他重要资源包括博客(例如 Régis Philibert and an entry by the Future Imperfect theme's creator) and the Hugo documentation 的博客。