使用 Jekyll 显示第一篇文章的引用
我正在尝试设置 Jekyll,以便在侧边栏中显示帖子列表中第一篇帖子的引用,但我不太清楚该怎么做。我在每篇文章的 Markdown 中的 YML Front Matter 中将引用文本定义为 quote
变量。
这是我的 default.html 的相关摘录:
<div id="content">
{{ content }}
</div>
<div id="sidebar">
<blockquote>{{ page.quote }}</blockquote>
</div>
这是我的 index.html:
---
layout: default
quote: ** Can a variable referencing the first post go here? **
---
{% for post in site.posts limit:10 %}
<h2>{{ post.title }}</h2>
<div class="post">
{{ post.content }}
</div>
{% endfor %}
I'm trying to set up Jekyll so that a quote from the first post in the list of posts is displayed in a sidebar, but I can't quite work out how to do it. I have the quote text defined as a quote
variable within the YML Front Matter in each post's Markdown.
This is the relevant extract from my default.html:
<div id="content">
{{ content }}
</div>
<div id="sidebar">
<blockquote>{{ page.quote }}</blockquote>
</div>
And this is my index.html:
---
layout: default
quote: ** Can a variable referencing the first post go here? **
---
{% for post in site.posts limit:10 %}
<h2>{{ post.title }}</h2>
<div class="post">
{{ post.content }}
</div>
{% endfor %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 default.html 中,
我认为您不能在 YML 问题中存储引用,但这应该得到您想要的。
and in default.html
I don't think you can store references in the YML matter but this should get what you want.
经过多次实验,我能够使用 default.html 中的 Liquid 代码片段解决问题:
After much experimentation, I was able to solve the problem using this Liquid snippet within default.html: