From 591b189aed2c548298da737243862210bdc267c9 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Tue, 4 Jun 2024 13:51:08 +0200 Subject: [PATCH] Fix authors in feed --- _plugins/gtn.rb | 21 ++++++++++----------- _plugins/gtn/contributors.rb | 8 ++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/_plugins/gtn.rb b/_plugins/gtn.rb index ad24d5abbc5ab6..3bb82e8b7cc65b 100644 --- a/_plugins/gtn.rb +++ b/_plugins/gtn.rb @@ -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| @@ -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__ diff --git a/_plugins/gtn/contributors.rb b/_plugins/gtn/contributors.rb index 0ac49646a8df65..ff36fb0b572f04 100644 --- a/_plugins/gtn/contributors.rb +++ b/_plugins/gtn/contributors.rb @@ -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 ##