gpt4 book ai didi

jekyll - Jekyll 按月发布的帖子

转载 作者:行者123 更新时间:2023-12-02 04:03:56 29 4
gpt4 key购买 nike

我正在尝试从我的网站创建帖子的存档页面。我希望能够以这种格式为每个月的帖子列表提供一个页面:

www.mywebsite.com/2016/11 将显示 2016 年 11 月的所有帖子。

我可以为我发布的每个月创建一个页面,每次我在新月份发布帖子时都会动态创建该页面吗?我不想每月手动创建一个新页面。

我已经可以按年份对帖子进行分组,如下所示:

<ul>
{% for post in site.posts %}
{% assign currentdate = post.date | date: "%Y" %}
{% if currentdate != date %}
<li id="y{{currentdate}}">{{ currentdate }}</li>
{% assign date = currentdate %}
{% endif %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>

感谢您的帮助。

最佳答案

您可以修改您的date过滤以整合月份,例如date: "%B %Y" 。这就是我在布局中使用的,带有单独的 <ul>每个月。

来自documentationdate 的仅月份值过滤器是:

  • %b :月份名称缩写。
  • %B :完整的月份名称。
  • %m :一年中的月份(01 - 12)。

完整循环:

<ul>
{% for post in site.posts %}
{% assign currentdate = post.date | date: "%B %Y" %}
{% if currentdate != date %}
<li id="y{{currentdate}}">{{ currentdate }}</li>
{% assign date = currentdate %}
{% endif %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>

关于生成页面,据我所知这只能通过插件来完成。如果您无法使用插件,例如如果您在 GitHub 上托管页面,您能做的最好的事情就是根据布局将页面缩减为简短的 YAML frontmatter,如 this answer 中所示。 .

关于jekyll - Jekyll 按月发布的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40444967/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com