Skip to content

Commit

Permalink
Fix authors in RSS feed by using site.data.authors instead of pages
Browse files Browse the repository at this point in the history
The jekyll-feed plugin doesn't know about our custom pages, but it
does support `site.data.authors` as a map. So, let's use that as
our "source of truth" instead.

Then, as secondary effect, generate author pages automatically
with a plugin from that data.
  • Loading branch information
Krinkle committed Jan 15, 2025
1 parent 1b7587f commit 9c25ef7
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 22 deletions.
2 changes: 2 additions & 0 deletions _data/authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alice: Alice Fitzgerald
jlind: James Lind
6 changes: 0 additions & 6 deletions _includes/author-text.html

This file was deleted.

2 changes: 1 addition & 1 deletion _includes/opengraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{% if page.layout == "post" and page.date and page.author %}
<meta property="og:type" content="article">
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}">
<meta name="author" content="{% include author-text.html author=page.author %}">
<meta name="author" content="{{ site.data.authors[include.author] | default: include.author | escape }}">
{% endif %}

{% endcapture -%}
Expand Down
4 changes: 2 additions & 2 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ <h1>{{ page.title | escape }}</h1>
<p class="post-meta byline">Posted on <a href="{{ page.url | relative_url }}" rel="bookmark"><time itemprop="pubdate" datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: date_format }}</time></a>{% if page.author %} by <span class="vcard"><span class="fn n" rel="author">
{%- assign author_page = site.pages | where: "layout", "posts-author" | where: "author", page.author | first -%}
{%- if author_page -%}
<a href="{{ author_page.url | relative_url }}">{{ author_page.title | escape }}</a>
{%- else -%}{{ page.author | escape }}
<a href="{{ author_page.url | relative_url }}">{{ site.data.authors[page.author] | default: page.author | escape }}</a>
{%- else -%}{{ site.data.authors[page.author] | default: page.author | escape}}
{%- endif -%}</span></span>{% endif %}</p>
</header>
{{ content }}
Expand Down
2 changes: 1 addition & 1 deletion _layouts/posts-tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Tag: {{ page.title | escape }}</h1>
{%- for post in posts -%}
<div class="post-row">
<h2><a href="{{ post.url | relative_url }}">{{ post.title | escape }}</a></h2>
<p class="post-meta">Posted on <time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: date_format }}</time>{% if post.author %} by {% include author-text.html author=post.author %}{% endif %}</p>
<p class="post-meta">Posted on <time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: date_format }}</time>{% if post.author %} by {{ site.data.authors[include.author] | default: include.author | escape }}{% endif %}</p>
<div class="post">
{{- post.excerpt -}}
{%- if post.excerpt != post.content %}
Expand Down
2 changes: 1 addition & 1 deletion _layouts/posts-year.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Archive: {{ page.date | date: '%Y' }}</h1>
{%- for post in posts -%}
<div class="post-row">
<h2><a href="{{ post.url | relative_url }}">{{ post.title | escape }}</a></h2>
<p class="post-meta">Posted on <time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: date_format }}</time>{% if post.author %} by {% include author-text.html author=post.author %}{% endif %}</p>
<p class="post-meta">Posted on <time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: date_format }}</time>{% if post.author %} by {{ site.data.authors[include.author] | default: include.author | escape }}{% endif %}</p>
<div class="post">
{{- post.excerpt -}}
{%- if post.excerpt != post.content %}
Expand Down
2 changes: 1 addition & 1 deletion _layouts/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>{{ page.title }}</h1>
{% for post in posts -%}
<div class="post-row">
<h2><a href="{{ post.url | relative_url }}">{{ post.title | escape }}</a></h2>
<p class="post-meta">Posted on <time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: date_format }}</time>{% if post.author %} by {% include author-text.html author=post.author %}{% endif %}</p>
<p class="post-meta">Posted on <time datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: date_format }}</time>{% if post.author %} by {{ site.data.authors[include.author] | default: include.author | escape }}{% endif %}</p>
<div class="post">
{{- post.excerpt -}}
{%- if post.excerpt != post.content %}
Expand Down
5 changes: 0 additions & 5 deletions author/alice.md

This file was deleted.

5 changes: 0 additions & 5 deletions author/jlind.md

This file was deleted.

34 changes: 34 additions & 0 deletions lib/jekyll-theme-amethyst.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,37 @@ def file_version_query(input, *filenames)
end

Liquid::Template.register_filter(Jekyll::AmethystFilters)

module AmethystPlugin

class AuthorPageWithoutAFile < Jekyll::PageWithoutAFile
def template
# The template of the permalink, can be customized e.g. to "/blog/author/:author/"
# for sites with both API docs and a blog.
site.config["amethyst"]["author_permalink"] || "/author/:author"
end

def url_placeholders
super.merge({
"author" => data["author"]
})
end
end

class AuthorPageGenerator < Jekyll::Generator
safe true

def generate(site)
site.data["authors"].each do |slug, name|
site.pages << AuthorPageWithoutAFile.new(site, site.source, 'author', "#{slug}.html").tap do |page|
page.data.merge!(
"layout" => "posts-author",
"title" => name,
"author" => slug
)
end
end
end
end

end

0 comments on commit 9c25ef7

Please sign in to comment.