From 991fa0c7c6358352037749f32a141f3f9f0f400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Wed, 9 Sep 2015 17:19:23 -0700 Subject: [PATCH] [docs] Use a generator to assign complete author data before generating site This makes sure that `post.author` will be the actual data we want and we don't have to assign it every time, potentially messing it up. --- _includes/blog_post.html | 7 +++---- _plugins/authors.rb | 14 ++++++++++++++ blog/all.html | 3 +-- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 _plugins/authors.rb diff --git a/_includes/blog_post.html b/_includes/blog_post.html index f960292a..a6978d12 100644 --- a/_includes/blog_post.html +++ b/_includes/blog_post.html @@ -1,5 +1,4 @@ {% assign page = include.page %} -{% assign author = site.data.authors[page.author] %}

{% if include.isPermalink %} @@ -12,10 +11,10 @@

{{ page.date | date: "%B %e, %Y" }} by - {% if author.url %} - {{ author.name }} + {% if page.author.url %} + {{ page.author.name }} {% else %} - {{ author.name }} + {{ page.author.name }} {% endif %}

diff --git a/_plugins/authors.rb b/_plugins/authors.rb new file mode 100644 index 00000000..9630e1f0 --- /dev/null +++ b/_plugins/authors.rb @@ -0,0 +1,14 @@ +# This transforms the data associated with each post, specifically the author. +# We store our author information in a yaml file and specify the keys in The +# post front matter. Instead of looking up the complete data each time we need +# it, we'll just look it up here and assign. This plays nicely with tools like +# jekyll-feed which expect post.author to be in a specific format. +module Authors + class Generator < Jekyll::Generator + def generate(site) + site.posts.each do |post| + post.data['author'] = site.data['authors'][post['author']] + end + end + end +end diff --git a/blog/all.html b/blog/all.html index f8efa0a9..ecb7cd71 100644 --- a/blog/all.html +++ b/blog/all.html @@ -9,8 +9,7 @@ id: all-posts

All Posts

{% for page in site.posts %} - {% assign author = site.data.authors[page.author] %} -

{{ page.title }} on {{ page.date | date: "%B %e, %Y" }} by {{ author.name }}

+

{{ page.title }} on {{ page.date | date: "%B %e, %Y" }} by {{ page.author.name }}

{% endfor %}