0

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?

  • It's not quite clear what exactly in your code isn't working. Is it the creation of the archive page that isn't working for you, or the posting of the author names in example 2? Do you want the archive page to automatically generate? – acsmith Sep 03 '13 at 16:54
  • It's the actual creation of the archive page to display a list each authors posts (example 2) that isn't working for me. I was thinking of generating the "archive" pages for each author dynamically and then simply using static links to link to each authors page from the sidebar – Justin Brown Sep 03 '13 at 23:54
  • Did that work for you at all? I'm curious to see whether the mode of building the index pages works. I know the `articles.select` notation is pretty inefficient, but considering it's a static site that seems okay. – acsmith Sep 05 '13 at 17:37
  • no I didn't have any luck unfortunately, but from what I can read into it the ideas were right, if I had a bit more time to persist with it.... – Justin Brown Sep 12 '13 at 12:43

1 Answers1

1

First of all, you will need to add the proxies in config.rb:

Middleman: Dynamic Pages

# 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>
acsmith
  • 1,466
  • 11
  • 16