5
votes

What I'm trying to do

We know Jekyll can use front matter variables like tags and categories and access them with site.tags and site.categories to iterate over them using liquid. Now my problem is that I can't do this with a custom front matter variable like author (as in site.authors) because Jekyll will not store it in a list format. This makes it very hard to paginate it.

The problem

Every solution I have looked at i.e.

requires me to hardcode a list of authors to _config.yml or some other .yml (i.e. in _data/authors.yml). The problem here is that I don't use a fixed list of authors. The authors list needs to get updated when I throw in another post with a front-matter tag author: exampleAuthor or a list of authors (as in multiple authors per post, as currently only possible with categories and tags as well), while the server is running. It works with tags and categories splendidly, but not with custom tags like authors.

The easiest solution would be having a site.authors list to iterate over and just extending it with a ruby plugin.

I haven't found a plugin that provides me with a solution and thinking this was a common problem that I'm probably not the first to have.

What I tried

I then looked at writing my own ruby plugin (Which is hard on it's own because of the lack of documentation. Maybe I'm to dumb to google, but the resources I found where very limited and hardly enough to guide you through the process) but there has to be a reason why this is so hard to do that makes all the existing solutions require hard coding the author list in a .yml (or .json, but most people go with .yml for some reason).

Doing this is out of the question for me, since I want to only throw in posts with author names in it later on and manipulating a .yml (I am under the impression that ymlfiles don't get compiled once the server is started, like _config.yml, correct me if I'm wrong) would be counterproductive because it requires you to restart the server to have them compiled.

Even very advanced plugins like jekyll-paginate-v2 (which I use successfully to paginate posts by tags and categories) don't have a solution to this as this issue portrays. He's getting recommended to abuse the category variable to paginate by author, which is kind of a desperate workaround.

I have found suggestions that it can be done with collections, however it does not seem feasible. Primarily due to the nature of their implementation: They require hard-coding the author list (again, I don't want that. I don't have a fixed list of authors. All of the author information has to come from the front-matter in the /_posts directory .md files) As of now I don't see how it can be done with collections. However I'm open to suggestions.

Edit: I found this dated issue on Jekylls github page which highlights that people are trying to do the same but to no avail. Has this become viable in the last 4 years?

1
Can you update the question with an example of what are you trying to do? I'm not sure I am understanding it right but it seems that you need a _data/authors.yml file with author usernames as indexes, then in your posts you just add the author username to an author attribute in front matter, and each post will have its own author metadata. - marcanuy
Do yml files get updated while the server is running? - blkpingu
for example? Jekyll is a static website generator, the static part means you have to update them by hand. - marcanuy
not at all. The server can update the html files in the _site directory in real time if you add posts to the _posts directory. No need to restart the server. I don't know if this is possible with .ymls, since _config.yml is not getting recompiled for technical reasons. In Terms of examples, I'd like to paginate authors. What to you mean, example? It is not hard to imagine what I mean by that. How well do you know Jekyll? No offence. - blkpingu
I guess that you said "no offence" because you know it was offensive? Please have a look at stackoverflow.com/conduct and jekyllrb.com/docs/usage - marcanuy

1 Answers

2
votes

Adding authors to Jekyll posts is easy with collections. Here's a proof of concept for you. Specifically, in this commit I add everything you need for it.

As for your question about pagination, will need to use a pagination plugin (paginate-v2 is good), as I believe the built in pagination only supports the posts collection.