Jekyll 中的作者存档页面

发布于 2024-12-29 06:12:34 字数 537 浏览 3 评论 0原文

我正在尝试在 Github 页面上使用 Jekyll 创建一个多作者博客。我将作者数组字段添加到 _config.yml 中,我可以在帖子模板上使用该数据。

_config.yml:

authors:
    muratcorlu:
        display_name: Murat Corlu
        avatar: 2906955ae59c795275979d3782d7bfca

posts.html

{% assign author = site.authors[page.author] %}

<p>Author: {{ author.display_name }}</p>

现在我想制作一个作者存档页面,其网址如 /authors/muratcorlu/ (即列出帖子作者:muratcorlu),但我不知道如何从网址获取作者姓名。

I'm trying to make a multiple author blog with Jekyll on Github pages. I added authors array field to _config.yml and I can use that data on posts template.

_config.yml:

authors:
    muratcorlu:
        display_name: Murat Corlu
        avatar: 2906955ae59c795275979d3782d7bfca

posts.html

{% assign author = site.authors[page.author] %}

<p>Author: {{ author.display_name }}</p>

Now I want to make an author archive page with a url like /authors/muratcorlu/ (i.e. listing posts authored by muratcorlu), but I don't know how can I get author name from url.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫儰鉨ミ守葔 2025-01-05 06:12:34

恐怕您无法自动创建这些页面。如果您有 5 位作者,则必须手动创建 5 个页面。页面可以使用相同的布局,这样就不会很痛苦。

这将是authors/muratcorlu.textile

---
layout: author
author: muratcorlu
---

您必须手动创建其中每一个。幸运的是,您不必执行任何其他操作 - 其余部分可以放入共享布局中,如下所示:

<ul>
{% for p in site.pages do %}
  {% if p.author == page.author %}
    <li><a href="{{ p.url }}">{{ p.title }}</a></li>
  {% endif %}
{% endfor %}
</ul>

I'm afraid you can't create those pages automatically. If you have 5 authors, you will have to create 5 pages manually. The pages can use the same layout, so it will not be very painful.

This would be authors/muratcorlu.textile

---
layout: author
author: muratcorlu
---

You would have to create each of those manually. Fortunately, you don't have to do anything else - the rest can be put in a shared layout that can look like this:

<ul>
{% for p in site.pages do %}
  {% if p.author == page.author %}
    <li><a href="{{ p.url }}">{{ p.title }}</a></li>
  {% endif %}
{% endfor %}
</ul>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文