首页 > 解决方案 > 文章列表中的 jekyll 作者图片

问题描述

如果我在集合中定义了 id,请问如何显示作者的个人形象:

我的收藏/_authors/

name: John Doe
image: assets/img/photo-john.jpg
layout: author
permalink: "/authors/john-doe/"

如何在文章循环中显示它?

{% for post in site.posts %}
    {% assign author = site.authors[page.author] %}
    <img src="{{ site.baseurl }}/{{ author.image }}" alt="{{ post.author }}" class="avatar avatar-sm">
{% endfor %}

标签: jekyllliquid

解决方案


{{ author.image }}和怎么样relative_url

我假设image是图像的网址。

在降价中

{% for post in site.posts %} 
{% assign author = site.authors[page.author] %} 

{: .avatar .avatar-sm }
![{{ post.author }}]({{ author.image | relative_url }})

{% endfor %}

在 html 中


{% for post in site.posts %} 
{% assign author = site.authors[page.author] %} 

<img src="{{ author.image | relative_url }}" alt="{{ post.author }}" class="avatar avatar-sm">

{% endfor %}

推荐阅读