Jekyll 中按月发布的帖子
Posts by month in Jekyll
我正在尝试从我的网站创建 posts 的存档页面。我想要的是能够以这种格式按月为每个 post 列表创建一个页面:
www.mywebsite.com/2016/11 将显示 2016 年 11 月的所有 post。
我可以为我 post 编辑的每个月创建一个页面,该页面在我每次 post 新月时动态创建吗?我不想每个月都手动创建一个新页面。
我已经可以像这样按年份对 post 进行分组了:
<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>
。
从 documentation 开始,date
过滤器的仅限月份的值是:
%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>
关于生成页面,AFAIK 这只能通过插件来完成。如果您不能使用插件,例如如果你在 GitHub 上托管你的页面,你能做的最好的事情就是将你的页面减少为依赖布局的短 YAML frontmatter,如 this answer.
我正在尝试从我的网站创建 posts 的存档页面。我想要的是能够以这种格式按月为每个 post 列表创建一个页面:
www.mywebsite.com/2016/11 将显示 2016 年 11 月的所有 post。
我可以为我 post 编辑的每个月创建一个页面,该页面在我每次 post 新月时动态创建吗?我不想每个月都手动创建一个新页面。
我已经可以像这样按年份对 post 进行分组了:
<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>
。
从 documentation 开始,date
过滤器的仅限月份的值是:
%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>
关于生成页面,AFAIK 这只能通过插件来完成。如果您不能使用插件,例如如果你在 GitHub 上托管你的页面,你能做的最好的事情就是将你的页面减少为依赖布局的短 YAML frontmatter,如 this answer.