【问题标题】:how can i create this gallery more efficiently using jekyll & liquid?如何使用 jekyll & Liquid 更有效地创建这个画廊?
【发布时间】:2012-03-24 20:08:10
【问题描述】:

我的画廊基于我的 twitter 引导 css 文件。我最终将 Kramdown 与内联 HTML+Markdown 一起使用,因为我无法让它以我希望的方式在 Liquid 中工作。

Kramdown解析的markdown模板如下:

---
layout: gallery
title: Gallery
group: dropnavigation
root: .\
---

{% include root %}

{::options parse_block_html="true" /}


<li class="span3">
<div class="thumbnail">
[![image](http://placehold.it/260x180)](#)

#####Thumbnail label

Thumbnail caption right here...
</div>
</li>

<li class="span3">
<div class="thumbnail">
[![image](http://placehold.it/260x180)](#)

#####Thumbnail label

Thumbnail caption right here...
</div>
</li>

画廊布局如下:

---
layout: core
---
{% include root %}

<div class="page-header">
  <h1 class="well">{{ page.title }} <small>{{ site.tagline }}</small></h1>
</div>


<ul class="thumbnails">
{{ content }}
</ul>

有没有办法做到这一点,让我只包含图像标签和标签,然后通过模板由 ul、li 和 div 类设置样式?也许通过某种循环?

【问题讨论】:

    标签: templates gallery markdown jekyll liquid


    【解决方案1】:

    是的。您可以通过定义一个包含每张图片信息的list 来循环执行此操作。

    ---
    layout: gallery
    title: Gallery
    group: dropnavigation
    root: .\
    
    pictures:
      - url: http://placehold.it/260x180
        label: Label 1
        caption: Caption 1
      - url: http://placehold.it/260x180
        label: Label 2
        caption: Caption 2
      - url: http://placehold.it/260x180
        label: Label 3
        caption: Caption 3
    ---
    
    {% include root %}
    
    {::options parse_block_html="true" /}
    
    {% for pic in page.pictures %}
     <li class="span3">
      <div class="thumbnail">
       [![image]({{ pic.url }})](#)
    
       ##### {{ pic.label }}
    
       {{ pic.caption }}
      </div>
     </li>
    {% endfor %}
    

    (这甚至可以通过将 YAML 标头与列表一起完成,并在画廊布局中完成循环和其他处理,因此您只需将 pictures 列表更改为拥有多个画廊(这将意味着标题和标签必须用 HTML 而不是 Markdown 编写)。编辑:例如,每个画廊文件都是这样的:

    ---
    layout: gallery
    title: Gallery
    group: dropnavigation
    root: .\
    
    pictures:
      - url: http://placehold.it/260x180
        label: Label 1
        caption: Caption 1
      - url: http://placehold.it/260x180
        label: Label 2
        caption: Caption 2
      - url: http://placehold.it/260x180
        label: Label 3
        caption: Caption 3
    ---
    

    图库模板如下所示:

    ---
    layout: core
    ---
    {% include root %}
    
    <div class="page-header">
      <h1 class="well">{{ page.title }} <small>{{ site.tagline }}</small></h1>
    </div>
    
    
    <ul class="thumbnails">
    {% for pic in page.pictures %}
     <li class="span3">
      <div class="thumbnail">
       <a href="#"><img src="{{ pic.url }}" alt="image" /></a>
       <h5>{{ pic.label }}</h5>
       <p>{{ pic.caption }}</p>
      </div>
     </li>
    {% endfor %}
    </ul>
    

    )

    【讨论】:

    • 谢谢,这是一个很好的解决方案!这是因为液体是模板语言吗?如果我使用不同的模板语言,是否可以在没有 YAML 头问题的情况下做到这一点?
    • @user1026169,for 循环的语法以及标头在 YAML 中的事实是因为 Liquid 是模板语言。标头包含有关页面的信息,因此即使在某些其他模板语言中,仍然需要一些包含该信息的元数据。
    • 是的,这很有意义。最后一个问题:如果我使用不同的静态网站生成器、模板引擎甚至布局语言 - 那么是否可以在不依赖元数据的情况下做到这一点?
    • @user1026169,您需要某种方式告诉生成器在图库中使用哪些图片/标题/等,以及每个页面使用什么模板,所以不,您将始终需要元数据,除非您正在完整地输入每一页。 (另外,我已经扩展了我在答案中的最后一句话,以防万一你没有注意到。)
    • 谢谢,我赞成你所有的答案。这消除了许多阻碍我的误解。我已经不必要地完整地做了很多页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多