我正在试验hugo和this theme。从回购中的示例网站我可以看到,帖子特色图像的配置方式如下:
featured = "pic.jpg"
featuredalt = "Pic 2"
featuredpath = "date"
要求我在pic.jpg
中放置static/img/YEAR/MONTH
。
有人可以解释一下,这条路径是如何从featuredpath = "date"
收集的?还有其他选择吗?也许相对于source.md文件?模板魔法发生here,但没有包含date
的内容。
答案 0 :(得分:1)
你走在正确的轨道上。您注意到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和entry by the Future Imperfect theme's creator)和Hugo documentation。