2
votes

I'm trying to create a Jekyll plugin to paginate author pages, but can't seem to get over the first hurdle.

I'm basing my attempt on an existing plugin, and I'm stumbling when trying to elect pages by author. The original plugin was for categories, and its site select looks like this:

category_posts = site.categories[page.data['category']].sort_by { |p| -p.date.to_f }

I was hoping something like this would work (my author info is contained in _data/authors.yml):

author_posts = site.data['authors'][page.data['author']].sort_by { |p| -p.date.to_f }

But that doesn't work. I've also tried:

author_posts = site.data.authors[page.data['author']].sort_by { |p| -p.date.to_f }

And that also falls (with a NOMETHOD error on 'author').

Does anyone have any suggestions on the correct way to do this?

Thanks.

2

2 Answers

2
votes

I can't speak to looking up pages by author, but I just found your post while trying to pull up the author's info on a given page, and I got it working. Maybe this will get you part of the way (or maybe you have already gotten this far). In _data/authors.yml I have:

josh:
  name: Josh Justice
  email: [email protected]
  twitter: CodingItWrong
  github: needbee

Then in a post I have:

---
title: Hello, world!
layout: post
author: josh
---

Then in the post layout I have:

<p>By <a href="https://twitter.com/{{ site.data.authors[page.author].twitter }}">
{{ site.data.authors[page.author].name }}
</a></p> 

Check the live site for the result, or take a look at or fork the repo.

EDIT:

Posted too soon; I ended up doing something similar, except the post itself doesn't show the author's other articles; there's a separate author page. And it's not in a plugin, but just in a template. But maybe the way I'm accessing the data structure will be helpful to you.

In authors/josh.html:

{% include author.html author="josh" %}

In includes/author.html:

{% for post in site.posts %}
  {% if post.author == include.author %}
    {% include post_summary.html post=post %}
  {% endif %}
{% endfor %}
0
votes

You can filter it like that way,

  {% assign filtered_posts = site.posts | where: 'author', page.author%}
  {% for post in filtered_posts %}