Skip to content

Commit b0bf35a

Browse files
committed
[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.
1 parent e97da42 commit b0bf35a

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

docs/_includes/blog_post.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{% assign page = include.page %}
2-
{% assign author = site.data.authors[page.author] %}
32

43
<h1>
54
{% if include.isPermalink %}
@@ -12,10 +11,10 @@ <h1>
1211
<p class="meta">
1312
{{ page.date | date: "%B %e, %Y" }}
1413
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>
1716
{% else %}
18-
{{ author.name }}
17+
{{ page.author.name }}
1918
{% endif %}
2019
</p>
2120

docs/_plugins/authors.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
<div class="inner-content">
1010
<h1>All Posts</h1>
1111
{% 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>
1413
{% endfor %}
1514
</div>
1615
</section>

0 commit comments

Comments
 (0)