jekyll - Jekyll - 无法获取 url 和作者姓名
问题描述
我正在尝试使用以下代码获取作者详细信息以显示在他们的博客附近
{% assign author = site.authors | where: 'name', post.author %}
{% if author %}
- <a href="{{ author.url }}">{{ author.name }}</a>
{% endif %}
当我尝试使用 {{ author }} 打印作者时,它会在视图中显示作者页面,但是当我尝试打印 {{author.url}} 或 {{author.name}} 之类的任何内容时,它不会打印任何事物。
此外,当我使用以下代码单独打印作者详细信息时,它会显示详细信息
{%- for aut in site.authors-%}
{{aut.name}}
{{aut.url}}
{%- endfor -%}
任何帮助,将不胜感激。
解决方案
{% assign author = site.authors | where: 'name', post.author %}
这将返回一个包含匹配元素的数组,或者nil
如果没有找到匹配元素。
如果匹配元素应该存在并且是唯一的,则可以使用第一个数组过滤器来获取它,如下所示:
{% assign author = site.authors | where: 'name', post.author | first %}
推荐阅读
- android - Edit and delete the item from recyclerview on swipe?
- flutter - I want to delay my future builder as a i await for a network call
- scala - 使用 sbt 构建凿子时,如何关闭进度条等以使输出干净?
- ruby-on-rails - friendly_id gem,更小的哈希?
- java - Looping Threads every 3 seconds in JavaFX
- android - 需要人脸锁支持
- python - 在 django sql 查询中使用 python 变量
- json - okhttp 返回空响应
- excel - 改变单元格颜色的函数
- django - Forbidden 403 您无权访问此资源。(mod_wsgi、wamp、apache2.4、django)在 Windows 上