如何使用 markdown 为我的博客 post 显示正确的标题而不仅仅是最新的标题

How to show the correct title for my blog post and not just the latest title using markdown

我正在尝试使用 markdown 在我的网站上创建博客,但我在设置博客标题时遇到了问题。 我创建了一个循环以将最新的标题和摘录引入我的主页,效果很好。: {% for post in site.posts limit: 1 %}

在我的网站上有我的博客列表 (https://jenjnif.github.io/blog.html) 当你点击一个阅读整个博客时,我会只显示该博客的标题。

我使用与上面相同的代码 {% for post in site.posts limit: 1 %} 只显示一个标题,因为所有博客标题都没有显示,但显然它只会无论我实际查看的是哪个博客,都显示最新的标题。这是该页面的降价:

---

布局:默认

---

<div id="post">
<div class="blog-header">
   {% for post in site.posts limit: 1 %}
</div>
<h2 class="blog-title">{{ post.title }}</h2>
{% endfor %}
{{ content }}
</div>

我知道限制:1 将不起作用,因为它只会采用最新的标题,但我不知道如何让每个博客上只显示一个标题 post。有没有办法确保只显示一个标题 - 只显示正确的当前博客标题,而不是所有标题? 所有文件都可以在我的 GitHub 存储库中找到:https://github.com/jenjnif/jenjnif.github.io

在使用 Jekyll 及其 Liquid 模板引擎时,它们有几个 sets of variables。您可以使用 page.title 获取当前博客 post.

的标题,而不是使用 for 循环遍历所有 posts
<div id="post">
<div class="blog-header">
</div>
<h2 class="blog-title">{{ page.title }}</h2>
{{ content }}
</div>