我对 Hugo 和 Netlify 都很陌生,所以我可能只是做错了。
我已经成功构建并部署了一个带有画廊的网站,使用Hugo https://hugodocs.info/, the Galleria https://galleria.io/插件,并部署到Netlify https://www.netlify.com/这一切都奏效了。但是,我想尝试使用网络内容管理系统 https://www.netlifycms.org/,并且正在努力将其设置为处理画廊功能(它对于仅编写文本帖子来说效果很好)
我不确定这是否是 Netlify CMS 的限制,或者我是否以不适合静态站点的方式制作画廊。
为了在 Hugo 中实现画廊,我在每篇文章的前面做了以下操作:
+++
date = "2017-02-13T23:17:09+01:00"
summary = "In which I fail to RTFM, visit a Lamasery, and eat a lot of fruit."
tags = []
title = "China 2017: Day 11"
[[galleria]]
imgSrc = "../images/china/11/Lama-Temple.JPG"
imgTitle = "Hall In The Lama Temple"
imgDesc = "One of the main halls of the Lama Temple."
[[galleria]]
imgSrc = "../images/china/11/Octagonal-Hall.JPG"
imgTitle = "Octagonal Hall"
imgDesc = "An octagonal building just inside the entrance of the Lama Temple"
.
.
.
+++
然后在布局页面中:
{{ if isset .Params "galleria" }}
<div class="galleria">
{{ range .Params.galleria}}
<img src="{{ .imgSrc }}" alt="{{ .imgTitle }}" data-title="{{ .imgTitle }}" data-description="{{ .imgDesc }}">
{{ end }}
</div>
{{ end }}
在 Netlify CMS 设置中,我尝试添加一个对象小部件:
- name: "galleria"
label: "Gallery"
widget: "object"
optional: true
fields:
- {label: "Title", name: "imgTitle", widget: "string"}
- {label: "Gallery Image", name: "imgSrc", widget: "image"}
- {label: "Description", name: "imgDesc", widget: "string"}
我还有两个问题:
(i) 该对象出现,但当然只出现一次。我该如何设置才能输入任意数量的图像?
(ii) 在构建时,我收到错误:ERROR 2017/05/28 22:37:20 Error while rendering "page": template: _default/single.html:23:15: executing "_default/single.html" at <.imgSrc>: can't evaluate field imgSrc in type interface {}
所以,即使试图将一张图像(和相关数据)放入帖子中,我似乎也做错了。