Jekyll 中间商产品和类别YAML数据文件
是否可以使用基于产品数据文件的标记和类别遍历数据文件?例如:Jekyll 中间商产品和类别YAML数据文件,jekyll,middleman,data-files,Jekyll,Middleman,Data Files,是否可以使用基于产品数据文件的标记和类别遍历数据文件?例如: # toys.yml - name: Fire Truck id: 1 description: Red category: Automobile url: toys/fire-truck tags: red, truck - name: Freight Train id: 2 description: Fast delivery mail url: toys/freight-train cate
# toys.yml
- name: Fire Truck
id: 1
description: Red
category: Automobile
url: toys/fire-truck
tags: red, truck
- name: Freight Train
id: 2
description: Fast delivery mail
url: toys/freight-train
category: Train
tags: freight, train, rail
我正在使用代理页面生成页面
data.toys.each do |t|
proxy toys.path, "toys.html", locals: { toy: t}, ignore: true
end
index.html.erb
模板将是:
<div class="toys">
<% data.toys.each do |t| %>
<h1><%= t.name %></h1>
<p><%= t.desription %></p>
<span class="category"><%= t.category %></span> // I would like this to be linked to generate categories based on the toys.yml file
<span class="tags"><%= t.tags %></span> // The same as category, generated tag pages based on the toys.yml
<% end %>
</div>
//我希望这个链接能够根据toys.yml文件生成类别
//与类别相同,基于toys.yml生成的标签页
我该怎么做?我是否应该创建:
- 单独的玩具页面,比如firetruck.md,不用担心生成页面和使用元数据作为创建类别和标记页面的方式
- 或者,我应该创建一个
可以用类别填充它,有没有办法将它链接到category.yml
唯一idtoys.yml
我正在学习静态页面,想知道如何在不构建db支持的应用程序的情况下实现此功能。您可以创建一个
category.html.erb
文件和代理,以便为toys.yml文件中的每个唯一类别创建一个类别页面
categories.each do |c|
proxy "#{c}.html", "category.html", locals: { category: c, toys: data.toys}, ignore: true
end
至于如何获得类别列表,可以在data.toys列表上使用标准的ruby操作
categories = data.toys.map {|t| t.category}.uniq
标记类似,但需要解析逗号分隔的列表
您还可以构建更复杂的数据类型,或者定义自己的Ruby Toy和Category类,然后将这些类传递给locals参数中的代理调用。例如,这将允许您让类别对象包含属于该类别的玩具对象列表。在这种情况下,ruby Enumerablegroupby
方法将非常有用