2017-05-31 76 views
2

我對Hugo和Netlify都很陌生,所以有可能我只是做錯了。與Hugo一起使用Netlify CMS - 使用畫廊創建帖子

我已經使用HugoGalleria插件以及部署到Netlify成功構建並部署了一個帶有畫廊的網站。這一切都奏效了。然而,我想嘗試使用Netlify CMS,並且正在努力設置它來處理畫廊功能(它只是在寫一個文本文件就可以了)

我不確定這是否是Netlify CMS的限制,或者如果我以不適合靜態網站的方式來製作畫廊。

爲了實現在雨果畫廊,我做的每一個職位的前面的問題如下:在Netlify CMS設置

{{ if isset .Params "galleria" }} 
    <div class="galleria"> 
    {{ range .Params.galleria}} 
    <img src="{{ .imgSrc }}" alt="{{ .imgTitle }}" data-title="{{ .imgTitle }}" data-description="{{ .imgDesc }}"> 
    {{ end }} 
    </div> 
    {{ end }} 

的:

+++ 
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" 

. 
. 
. 
+++ 

然後在頁面佈局我嘗試添加一個對象部件:

- 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)物體出現,但當然只有一次。我如何設置它以允許我輸入儘可能多的圖像?

(二)關於構建,我得到一個錯誤: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 {}

這樣看來我做錯了什麼,甚至在嘗試後獲得一個圖像(及相關數據)。

回答

6

把它放在這裏是爲了防止其他人卡在這裏。

四處詢問後,並感謝在Netlify通道的Gitter可愛的人:

我應該用一個列表窗口小部件,而不是一個對象。該YAML現在看起來是這樣的:

- name: "galleria" 
     label: "Gallery" 
     widget: "list" 
     optional: true 
     fields: 
      - {label: "Title", name: "imgTitle", widget: "string"} 
      - {label: "Gallery Image", name: "imgSrc", widget: "image"} 
      - {label: "Description", name: "imgDesc", widget: "string"} 

這已經刪除生成錯誤,並提供我的CMS編輯器,我希望我可以添加多個(或幾個)圖像的小部件。

我現在遇到了後續問題,其中使用CMS創建的帖子被正確創建,出現在回購庫中的正確文件夾中,但是404。 。 。

+1

你有沒有得到第二個問題的答案?這聽起來像是您的Hugo主題不包含在子模塊中引起的。如果沒有正確的包含,buildbot沒有找到它,並且頁面沒有被構建。你可以通過從主題文件夾中刪除.git文件夾來解決這個問題,或者你可以[使用git-submodule包含它](http://choomnuan.com/blog/2015/07/18/how-to-setup-hugos -theme-使用-GIT-子模塊/)。 (由於這是次要的主要問題,我只是鏈接到一些指令,而不是寫在評論中) –

+0

404是由開發人員錯誤 - baseURL(顯然)不工作,而在測試時當網站網址被設置爲我的合適域名時,netlify域名 –