Jekyll:在Markdown中处理图像

时间:2015-03-13 15:39:12

标签: image markdown jekyll image-gallery

我的帖子页面设计由文字和图片组成,更具体地说是画廊。请看下面的插图:

enter image description here

我已经让这些画廊设置了我的前提:

---
gallery-1:
  rows:
    - images:
      -  { url: '1.jpg'}
    - images:
      -  { url: '2.jpg'}
      -  { url: '3.jpg'}
gallery-2:
  rows:
    - images:
      -  { url: '4.jpg'}
      -  { url: '5.jpg'}
---

有没有办法将这些图库打印到.md文件的页面上。我知道下面的代码不起作用,但类似的东西?

This is my markdown

[gallery-1]

This is more markdown

[gallery-2]

Jekyll有可能这样吗?

对此有任何帮助表示赞赏。提前谢谢!

1 个答案:

答案 0 :(得分:1)

首先,让我们简化您的yaml front matter

---
galleries:
 # gallery number one
 1:
   # row one in gallery one
   -
     - { url: '1.jpg', alt: 'alt 1'}
   # row two in gallery one
   -
     - { url: '2.jpg', alt: 'alt 2'}
     - { url: '3.jpg', alt: 'alt 3'}

 # gallery number two
 2:
  # row one in gallery two
   -
     - { url: '4.jpg', alt: 'alt 4'}
     - { url: '5.jpg', alt: 'alt 5'}

您的.md文件:

Markdown
{% include gallery.html  gallery=1 %}
Other markdown
{% include gallery.html  gallery=2 %}

然后是_includes/gallery.html文件:

{% comment %}-----------------
  - This page receives a gallery index (include.gallery)
  - It then assign the gallery[include.gallery] to the rows variable
%}-----------------{% endcomment %}
{% assign rows = page.galleries[include.gallery] %}

{% comment %}%}-----------------
  We now loop over rows
%}-----------------{% endcomment %}
{% for row in rows %}
<div class="row">
    {% comment %}%}-----------------
      and then loop over images in row
    %}-----------------{% endcomment %}
    {% for img in row %}
        <p>src="{{ site.baseurl }}{{ img.url }}" alt="{{ img.alt }}"</p>
    {% endfor %}
</div>
{% endfor %}

请参阅yaml documentationJekyll template documentation

相关问题