Skip to content

Commit 907448b

Browse files
committed
improve author handling (support multiple authors and missing authors)
1 parent 6422f0d commit 907448b

File tree

7 files changed

+65
-73
lines changed

7 files changed

+65
-73
lines changed

models/blog-post.ini

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ width = 1/2
2424

2525
[fields.author]
2626
label = Author
27-
type = select
28-
// TODO: this is far too opaque, fix this. basically its finding authors by
29-
// going up to entries.blog, then getting everything in
30-
// the blog.authors.<author name> files
31-
source = record.parent.parent.children.get('authors').children.all()
27+
type = strings
3228

3329
[fields.body]
3430
label = Body

themes/vocabulary_theme/templates/blocks/recent-posts.html

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% from "macros/author_name.html" import render_author_name %}
1+
{% from "macros/posts.html" import render_post_summary %}
22

33
<section class="recent-posts">
44
<div class="container">
@@ -12,28 +12,9 @@ <h2 class="is-paddingless level-left">
1212
</div>
1313
<div class="columns">
1414
{% for post in site.query('/blog/entries') %}
15-
{% if loop.index <= 3 %}
16-
{% set author = post.parent.parent.children.get('authors').children.get(post.author) %}
17-
<div class="column is-one-third is-paddingless padding-horizontal-big padding-top-bigger">
18-
<article class="card entry-post horizontal no-border blog-entry">
19-
{% if author.about %}
20-
<header>
21-
<figure class="image blog-image">
22-
<img class="profile" src="https://secure.gravatar.com/avatar/{{ author.md5_hashed_email }}?size=200&d=mp" alt="gravatar" />
23-
</figure>
24-
</header>
25-
{% endif %}
26-
</header>
27-
<div class="blog-content">
28-
<h4 class="b-header"><a class="blog-title" href="{{ post|url }}">{{ post.title }}</a></h4>
29-
<span class="blog-author">by <a class="author-name" href="{{ author|url }}">{{ render_author_name(author) }}</a>
30-
on {{ post.pub_date|dateformat("YYYY-MM-dd") }}</span>
31-
<div class="excerpt">
32-
{{ post.body | excerpt | string | striptags() | truncate(100) }}
33-
</div>
34-
</div>
35-
</article>
36-
</div>
15+
{% set post_loop = loop %}
16+
{% if post_loop.index <= 3 %}
17+
{{ render_post_summary(post) }}
3718
{% endif %}
3819
{% endfor %}
3920
</div>

themes/vocabulary_theme/templates/blog-post.html

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
{% extends "layout.html" %}
2-
3-
{% from "macros/author_name.html" import render_author_name %}
4-
2+
{% from "macros/authors_byline.html" import render_authors_byline %}
3+
{% from "macros/authors_gravatar.html" import render_author_gravatar %}
54
{% from "macros/posts.html" import render_posts %}
65

76
{% block title %}{{ this.title }}{% endblock %}
87

9-
{% set author = this.parent.parent.children.get('authors').children.get(this.author) %}
10-
118
{% block body %}
129
<div class="single-post">
1310
<header class="single-post-header">
1411
<div class="container">
1512
<h4>CC Open Source Blog</h4>
1613
<h2 class="title">{{ this.title }}</h2>
17-
{{ check_file('content' + this.parent.parent.path + '/authors/' + this.author + '/contents.lr') }}
1814
<div class="author columns is-marginless">
19-
<figure class="image profile">
20-
<img src="https://secure.gravatar.com/avatar/{{ author.md5_hashed_email }}?size=200&d=mp" alt="gravatar" class="profile" />
21-
</figure>
22-
<p class="column">by <a href="{{ author|url }}">{{ render_author_name(author) }}</a>
23-
on {{ this.pub_date|dateformat("YYYY-MM-dd") }}</p>
15+
{{ render_author_gravatar(this) }}
16+
<p class="padding-small">
17+
{{ render_authors_byline(this) }}
18+
</p>
2419
</div>
2520
{% if this.series|length %}
2621
{% set series = this.parent.parent.children.get('series').children.get(this.series) %}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
{% from "macros/author_name.html" import render_author_name %}
1+
{% from "macros/posts.html" import render_post_summary %}
22

33
{% macro render_author_posts(posts) %}
4-
<div class="columns is-multiline">
4+
<div class="columns is-multiline blog-entries">
55
{% for post in posts %}
6-
{% set author = post.parent.parent.children.get('authors').children.get(post.author) %}
7-
<article class="card entry-post horizontal no-border blog-entry column is-one-third">
8-
<div class="blog-content">
9-
<h4 class="b-header"><a class="blog-title has-color-dark-slate-gray" href="{{ post|url }}">{{ post.title }}</a></h4>
10-
<span class="blog-author">by <a href="{{ author|url }}">{{ render_author_name(author) }}</a>
11-
on {{ post.pub_date|dateformat("YYYY-MM-dd") }}</span>
12-
<div class="excerpt">
13-
{{ post.body | excerpt | string | striptags() | truncate(100) }}
14-
</div>
15-
</div>
16-
</article>
6+
{{ render_post_summary(post, true) }}
177
{% endfor %}
188
</div>
199
{% endmacro %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% from "macros/author_name.html" import render_author_name %}
2+
3+
{% macro render_authors_byline(post) %}
4+
{% if post.author|length %}
5+
{% for author in post.author %}
6+
{% set author_loop = loop %}
7+
{% set current_author = post.parent.parent.children.get('authors').children.get(author) %}
8+
{% if author_loop.first %}by{% else %},{% endif %}
9+
{% if current_author %}
10+
{{ check_file('content' + post.parent.parent.path + '/authors/' + author + '/contents.lr') }}
11+
<a class="author-name" href="{{ current_author|url }}">
12+
{{ render_author_name(current_author) }}
13+
</a>
14+
{% else %}
15+
{{ author }}
16+
{% endif %}
17+
{% endfor %}
18+
{% endif %}
19+
on {{ post.pub_date|dateformat("YYYY-MM-dd") }}</span>
20+
{% endmacro %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% macro render_author_gravatar(post, skip_gravatar=false) %}
2+
{% if not skip_gravatar %}
3+
{# only display gravatar for first author so layout is broken #}
4+
{% set author = post.author[0] %}
5+
{% set current_author = post.parent.parent.children.get('authors').children.get(author) %}
6+
<header>
7+
<figure class="image blog-image">
8+
<img class="profile" src="https://secure.gravatar.com/avatar/{{ current_author.md5_hashed_email }}?size=200&d=mp" alt="gravatar" />
9+
</figure>
10+
</header>
11+
{% endif %}
12+
{% endmacro %}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
{% from "macros/author_name.html" import render_author_name %}
1+
{% from "macros/authors_byline.html" import render_authors_byline %}
2+
{% from "macros/authors_gravatar.html" import render_author_gravatar %}
3+
4+
{% macro render_post_summary(post, skip_gravatar=false) %}
5+
<div class="column is-one-third is-paddingless padding-horizontal-big padding-top-bigger">
6+
<article class="card entry-post horizontal no-border blog-entry">
7+
{{ render_author_gravatar(post, skip_gravatar) }}
8+
<div class="blog-content">
9+
<h4 class="b-header"><a class="blog-title" href="{{ post|url }}">{{ post.title }}</a></h4>
10+
{{ render_authors_byline(post) }}
11+
<div class="excerpt">
12+
{{ post.body | excerpt | string | striptags() | truncate(100) }}
13+
</div>
14+
</div>
15+
</article>
16+
</div>
17+
{% endmacro %}
218

319
{% macro render_posts(posts) %}
420
<div class="columns is-multiline blog-entries">
521
{% for post in posts %}
6-
{% set author = post.parent.parent.children.get('authors').children.get(post.author) %}
7-
<div class="column is-one-third">
8-
<article class="card entry-post horizontal no-border blog-entry">
9-
{% if author.about %}
10-
<header>
11-
<figure class="image blog-image">
12-
<img class="profile" src="https://secure.gravatar.com/avatar/{{ author.md5_hashed_email }}?size=200&d=mp" alt="gravatar" />
13-
</figure>
14-
</header>
15-
{% endif %}
16-
<div class="blog-content">
17-
<h4 class="b-header"><a class="blog-title" href="{{ post|url }}">{{ post.title }}</a></h4>
18-
<span class="blog-author">by <a href="{{ author|url }}">{{ render_author_name(author) }}</a>
19-
on {{ post.pub_date|dateformat("YYYY-MM-dd") }}</span>
20-
<div class="excerpt">
21-
{{ post.body | excerpt | string | striptags() | truncate(100) }}
22-
</div>
23-
</div>
24-
</article>
25-
</div>
22+
{% set post_loop = loop %}
23+
{{ render_post_summary(post) }}
2624
{% endfor %}
2725
</div>
2826
{% endmacro %}

0 commit comments

Comments
 (0)