Jekyll YAML画廊

时间:2015-12-08 15:55:13

标签: grid yaml jekyll

我有一个页面显示我的项目在网格布局中从yaml文件中提取。我无法弄清楚如何为各个页面提取正确的数据。

Yaml文件(portfolio.yaml)的格式如下:

- name: gallery one
  url: "/portfolio/gallery-one.html"
  thumbnail: /images/thumbnail.png
  decription: "Lorem ipsum dolor sit amet, consectetur adipisicing elit." 
- name: gallery two
  url: "/portfolio/gallery-one.html"
  thumbnail: /images/thumbnail.png
  decription: "Lorem ipsum dolor sit amet, consectetur adipisicing elit."

网格代码(工作正常)

{% for project in site.data.portfolio %}
      {{ project.url }}
      {{ project.thumbnail }}
 {% endfor %}

1 个答案:

答案 0 :(得分:0)

使用数据文件配置并不容易。 像这样重新整理你的文件:

gallery one:
  url: "/portfolio/gallery-one.html"
  thumbnail: /images/thumbnail.png
  decription: "Lorem ipsum dolor sit amet, consectetur adipisicing elit."

gallery two:
  url: "/portfolio/gallery-one.html"
  thumbnail: /images/thumbnail.png
  decription: "Lorem ipsum dolor sit amet, consectetur adipisicing elit."

然后,您可以制作一个将由所有项目页面使用的布局:

<强> _layouts / portfolio.html

---
layout: default
---
{% assign project = site.data.portfolio[page.project] %}
<h1>{{ page.title }}</h1>
<p>{{ project.decription }}</p>
{{ content }}

然后项目页面如下所示:

<强>廊-one.html

---
layout: portfolio
title: Gallery one
project: gallery one
---
additional content can go here

如果您有很多项目,可以查看可以自动生成页面的jekyll collections