I am creating a blog in the current version of Middleman and I want to be able to create a list of all the authors on the blog to display on a sidebar (just as I would a tag, that would then link to a page that listed all authors posts (sort of like a author archive?)
So far I have a "author" frontmatter block at the top of each page:
---
author: Joe Bloggs
---
I have thought of doing this using front matter but frontmatter only seems to allow page specific variables, eg:
---
layout: "blog"
authors:
- author 1
- author 2
- author 3
---
<ul>
<% current_page.data.authors.each do |f| %>
<li><%= f %></li>
<% end %>
</ul>
and not creating the archive page.
I thought I could do this similarly to how a tag list is displayed:
<ul>
<% blog.tags.each do |tag, articles| %>
<li><%= link_to tag, tag_path(tag) %></a></li>
<% end %>
</ul>
but so far no luck. I have done google searches but no specific were found.
Can anyone suggest a possible code solution?
First of all, you will need to add the proxies in config.rb:
# Assumes the file source/author/template.html.erb exists
["tom", "dick", "harry"].each do |name|
proxy "/author/#{name}.html", "/author/template.html", :locals => { :person_name => name }, :ignore => true
end
The problem, though, is that the middleman-blog engine doesn't seem to officially support different authors for each post. Read through this tutorial for a full explanation of a homebrewed solution: Building a Middleman Blog
Basically, you will want to do something like this on your archive page template:
# Note the presence of the person_name local variable, created in the above example
<% author_articles = articles.select {|x| x.data.author == person_name } %>
<ul>
<% author_articles.each do |article|
# Add your rendering code here %>
<li><%= link_to article.title, article.url %></li>
<% # (for better practices, put this in a helper method)
end %>
</ul>