@samitouri / QOS-React-2 / commits / b0bf35a361

[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.

Paul O’Shannessy committed Sep 9, 2015 at 17:19 UTC b0bf35a361bb5b1af9acdaed26f9f4adcc1e87ba
3 files changed +18 -6
docs/_includes/blog_post.html
+3 -4
@@ -1,5 +1,4 @@
1 {% assign page = include.page %}
2 -{% assign author = site.data.authors[page.author] %}
2
3 <h1>
4 {% if include.isPermalink %}
@@ -12,10 +11,10 @@
11 <p class="meta">
12 {{ page.date | date: "%B %e, %Y" }}
13 by
15 - {% if author.url %}
16 - <a href="{{author.url}}">{{ author.name }}</a>
14 + {% if page.author.url %}
15 + <a href="{{page.author.url}}">{{ page.author.name }}</a>
16 {% else %}
18 - {{ author.name }}
17 + {{ page.author.name }}
18 {% endif %}
19 </p>
20
docs/_plugins/authors.rb new
+14
@@ -0,0 +1,14 @@
1 +# This transforms the data associated with each post, specifically the author.
2 +# We store our author information in a yaml file and specify the keys in The
3 +# post front matter. Instead of looking up the complete data each time we need
4 +# it, we'll just look it up here and assign. This plays nicely with tools like
5 +# jekyll-feed which expect post.author to be in a specific format.
6 +module Authors
7 + class Generator < Jekyll::Generator
8 + def generate(site)
9 + site.posts.each do |post|
10 + post.data['author'] = site.data['authors'][post['author']]
11 + end
12 + end
13 + end
14 +end
docs/blog/all.html
+1 -2
@@ -9,8 +9,7 @@ id: all-posts
9 <div class="inner-content">
10 <h1>All Posts</h1>
11 {% for page in site.posts %}
12 - {% assign author = site.data.authors[page.author] %}
13 - <p><strong><a href="/react{{ page.url }}">{{ page.title }}</a></strong> on {{ page.date | date: "%B %e, %Y" }} by {{ author.name }}</p>
12 + <p><strong><a href="/react{{ page.url }}">{{ page.title }}</a></strong> on {{ page.date | date: "%B %e, %Y" }} by {{ page.author.name }}</p>
13 {% endfor %}
14 </div>
15 </section>