【发布时间】:2014-03-25 16:43:55
【问题描述】:
按照https://stackoverflow.com/a/9857308/2966190 的回答,我在 Jekyll 中实现了一个简单的照片库。
_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 中是否可以包含换行符?
【问题讨论】:
标签: templates gallery markdown jekyll liquid