Json 比较来自不同Jekyll_数据文件的数据
为了设置场景,我将作者信息存储在directory.json中,在我的Jekyll\u数据文件夹中Json 比较来自不同Jekyll_数据文件的数据,json,jekyll,liquid,Json,Jekyll,Liquid,为了设置场景,我将作者信息存储在directory.json中,在我的Jekyll\u数据文件夹中 "name": "Brandon Bellew", "bio": "Brandon Bellew is a great writer.", "email": "hal@eta.org", "specialties": "introspection, ventilation systems, memorization, post-prandial revelry",
"name": "Brandon Bellew",
"bio": "Brandon Bellew is a great writer.",
"email": "hal@eta.org",
"specialties": "introspection, ventilation systems, memorization, post-prandial revelry",
"photo": "http://www.tpgweb2.net/headshots/thumbs/brandon-b-thumb-2.jpg"
我还将文章信息存储在catalog.json中,也存储在我的Jekyll\u数据文件夹中
"name": "Beginner's Guide to Google Analytics",
"author": "Brandon Bellew",
"date": "May 18 2016",
"description": "The Google Analytics (GA) dashboard is quite intuitive, and it's easy to collect basic information (number of users on the site, average time spent on site, etc.) without having a deep background in analytics. But what about specifics?",
"category": "Analytics"
我试图循环浏览catalog.json文件中的所有文章,并显示文章信息,但从directory.json文件中的正确作者处提取照片
本质上,我试图让它做的是:如果目录中某篇文章的“作者”与目录项中某位作者的“姓名”匹配,则显示与该作者相关的照片。这样,我就不必为他们写的每一篇文章都将作者的照片单独存储在一个项目中
以下是我从目录中的正确作者处提取照片的失败尝试:
<h4>Articles</h4>
{% for item in site.data.catalogue %}
{% for item in site.data.directory %}
{% if item.name == page.author %}
<img src="{{ item.photo }}" >
{% endif %}
{% endfor %}
{% endfor %}
文章
{site.data.catalog%中项目的%s}
{site.data.directory%中项目的%s}
{%if item.name==page.author%}
{%endif%}
{%endfor%}
{%endfor%}
这是否可能使用Jekyll,或者我是否需要另一种方式来构建它 我相信删除重复的
项
引用将修复您当前的代码:
{% for catalogue in site.data.catalogue %}
{% for item in site.data.directory %}
{% if item.name == catalogue.author %}
<img src="{{ item.photo }}" >
{% endif %}
{% endfor %}
{% endfor %}
然后您可以像这样访问图像(您可以对此进行改进,以检查作者是否存在):
{%用于site.data.catalog%}
{%endfor%}
您可以使用where
这样的过滤器:
{% for article in site.data.catalogue %}
{% assign author = site.data.directory | where: 'name', article.author | first %}
{% if author %}<img src="{{ author.photo }}" >{% endif %}
{% endfor %}
{% endfor %}
{%用于site.data.catalog%中的文章]
{%assign author=site.data.directory |其中:'name',article.author | first%}
{%if作者%}{%endif%}
{%endfor%}
{%endfor%}
{% for catalogue in site.data.catalogue %}
<img src="{{ site.data.authors[catalogue.author].photo }}" >
{% endfor %}
{% for article in site.data.catalogue %}
{% assign author = site.data.directory | where: 'name', article.author | first %}
{% if author %}<img src="{{ author.photo }}" >{% endif %}
{% endfor %}
{% endfor %}