Skip to content

Commit d3e3cbb

Browse files
authored
Merge pull request #815 from BlackPythonDevs/issue-707-author-list
Refactor author frontmatter to list
2 parents 6650912 + 0c2960b commit d3e3cbb

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

.frontmatter_check.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ patterns:
88
- field_name: lang
99
- field_name: layout
1010
- field_name: title
11-
- field_name: author

_layouts/blog-list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h2><a href="{{ page }}.html">
1212
{% if page.description %}
1313
<p>{{page.description}}</p>
1414
{% endif %}
15-
<small>{{page.author | join(", ")}} - <strong>{{page.date | format_datetime}}</strong></small>
15+
<small>{% if page.author %}{{page.author | join(", ")}} - {% endif %}<strong>{{page.date | format_datetime}}</strong></small>
1616
</div>
1717
</article>
1818
{% endfor %}

_layouts/event-list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h1>{{title}}</h1>
77
<h2><a href="{{ page }}.html">
88
{{ page.title }}
99
</a></h2>
10-
<small>{{page.author}} {{page.date}}</small>
10+
<small>{% if page.author %}{{page.author | join(", ")}} {% endif %}{{page.date}}</small>
1111
</article>
1212
{% endfor %}
1313
</section>

_layouts/post.html

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
<header class="post-header">
1616
<h1 class="post-title p-name" itemprop="name headline">{{ title }}</h1>
1717
<p class="post-meta">
18+
{% if author %}
1819
<span itemprop="author" itemscope itemtype="http://schema.org/Person">
1920
{% for person in author %}
2021
<span class="p-author h-card" itemprop="name">{{ person }}</span>
2122
{% if not loop.last %}, {% endif %}
2223
{% endfor %}
2324
</span>
24-
25+
{% endif %}
2526
</p>
2627
</header>
2728
<div class="post-content e-content" itemprop="articleBody">
@@ -30,13 +31,17 @@ <h1 class="post-title p-name" itemprop="name headline">{{ title }}</h1>
3031
</article>
3132
</section>
3233

33-
{% set author = authors %}
3434
<section>
35-
{% if author and author.bio %}
36-
<hr />
37-
<h3>About {{author.name}}</h3>
38-
<p>{{author.bio|e}}</p>
39-
</section>
35+
{% if author %}
36+
{% for author_name in author %}
37+
{% set author_data = SITE_AUTHORS | selectattr("name", "equalto", author_name) | first %}
38+
{% if author_data and author_data.bio %}
39+
<hr />
40+
<h3>About {{author_data.name}}</h3>
41+
<p>{{author_data.bio|e}}</p>
42+
{% endif %}
43+
{% endfor %}
4044
{% endif %}
45+
</section>
4146

4247
{% endblock %}

app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
app.site_vars["navigation"] = navigation
3232
app.site_vars["DATETIME_FORMAT"] = "%d %b %Y"
3333
app.site_vars["year"] = str(datetime.date.today().year)
34+
app.site_vars["SITE_AUTHORS"] = json.loads(
35+
pathlib.Path("_data/authors.json").read_text()
36+
)
3437

3538

3639
@app.page

scripts/check_author_list.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def check_authors():
1717
if not isinstance(author, list):
1818
print(f"Error: Author in {file_path} is not a list: {author}")
1919
failed = True
20+
elif len(author) == 0:
21+
print(
22+
f"Error: Author list in {file_path} is empty. Remove the field if there is no author."
23+
)
24+
failed = True
2025
except Exception as e:
2126
print(f"Error processing {file_path}: {e}")
2227
failed = True

0 commit comments

Comments
 (0)