Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authors in feed #4991

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions _plugins/gtn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,17 +746,6 @@ def group_icons(icons)
Liquid::Template.register_filter(Jekyll::GtnFunctions)

##
# This does post-modification to every page
# Mapping the authors to their human names, and copying the cover (when present) to 'image'
#
# This exists because the jekyll-feed plugin expects those fields to look like that.
Jekyll::Hooks.register :posts, :pre_render do |post, _out|
post.data['author'] = Gtn::Contributors.get_authors(post.data).map do |c|
Gtn::Contributors.fetch_name(post.site, c)
end.join(', ')
post.data['image'] = post.data['cover']
end

# We're going to do some find and replace, to replace `@gtn:contributorName` with a link to their profile.
Jekyll::Hooks.register :site, :pre_render do |site|
site.posts.docs.each do |post|
Expand Down Expand Up @@ -878,6 +867,16 @@ def group_icons(icons)
(page.data['date_end'] - page.data['date_start']).to_i + 1
end
end

# This exists because the jekyll-feed plugin expects those fields to look like that.
posts.each do |post|
post.data['author'] = Gtn::Contributors.get_authors(post.data).map do |c|
Gtn::Contributors.fetch_name(post.site, c)
end.join(', ')
if post.data.key? 'cover'
post.data['image'] = post.data['cover']
end
end
end

if $PROGRAM_NAME == __FILE__
Expand Down
8 changes: 4 additions & 4 deletions _plugins/gtn/contributors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def self.get_contributors(data)
# +Array+ of contributor IDs
def self.get_authors(data)
if data.key?('contributors')
data['contributors']
data['contributors'] || []
elsif data.key?('contributions')
data['contributions']['authorship']
data['contributions']['authorship'] || []
else
[]
end

[]
end

##
Expand Down
Loading