繼在https://stackoverflow.com/a/9857308/2966190的答案我在Jekyll實現了一個簡單的照片庫。Jekyll通過YAML頁眉列表中的圖庫
_layouts/photos.html:
---
layout: layout
---
<section class="content">
<h1>
<a href="{{ page.url }}">{{ page.title }}</a>
</h1>
<section class="byline">
{{ page.date | date: "%B %e, %Y" }}
</section>
{% for pic in page.photos %}
<a href="{{ pic.url }}"><img src="{{ pic.url }}" alt="{{ pic.alt }}" /></a>
{% if pic.caption %}<p>{{ pic.caption }}</p>{% endif %}
{% endfor%}
{{ content }}
</section>
,這樣我可以簡單地做一個清單,所有需要的信息,並自動生成的畫廊,以這樣的方式:
example_gallery.md:
---
layout: photos
title: SOME TITLE
photos:
- url: /path/to/img1.png
alt: alt1
caption: Caption with [hyperlinks](example.com) formatted [three][ways] [that][fail]
[fail]: failure.com/sadface
- url: /path/to/img2.png
alt: alt2.
caption: Caption with <a href="/explicit/html/tags.html"> that work but hurt the eyes, are annoying to write, and don't allow me to separate formatting from content</a>.
---
[ways]: doesntwork.com
我遇到同樣的錯誤,其格式與標題爲img1一樣。
讀取文件錯誤/path/to/example_gallery.md:():沒有找到預期的關鍵,而在第7行列解析塊映射4
它也沒有,如果我把這個定義[link]
與caption:
相同(不含換行符)。
在上面的鏈接示例中,作者明確提到markdown在標題中不可用。爲了嘗試解決這個問題,我試圖在photos.html版面中更改{{ pic.caption }}
到{{ pic.caption | markdownify }}
,但都無濟於事。
所以,我的問題是:是否有一種方法可以通過編輯每張照片的佈局或YAML來讓圖像標題中的markdown工作(即不需要編寫插件,如How can I build a gallery tag for Jekyll?)?看起來類似的東西在摘錄中起作用(例如,請參閱:Include jekyll/liquid template data in a YAML variable? [我不需要在標題中使用液體標籤,正如在答案中討論的那樣))。
順便說一下,caption
有可能在它裏面有換行符嗎?
訣竅是切換到kramdown!謝謝! – evanb