From e384fc27ff7276ef929af62ef1b5db236a94586a Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 11 Jul 2023 09:42:39 +0200 Subject: [PATCH] citeproc --- app/models/research/hal/publication.rb | 17 ++++++++++++----- ...ors_citeproc_to_research_hal_publications.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20230711073707_add_authors_citeproc_to_research_hal_publications.rb diff --git a/app/models/research/hal/publication.rb b/app/models/research/hal/publication.rb index 25786b900..d400e147d 100644 --- a/app/models/research/hal/publication.rb +++ b/app/models/research/hal/publication.rb @@ -60,7 +60,9 @@ class Research::Hal::Publication < ApplicationRecord 'abstract_s', 'openAccess_bool', 'journalTitle_s', - 'authLastNameFirstName_s', + 'authFullName_s', + 'authLastName_s', + 'authFirstName_s', 'files_s' # '*', ] @@ -87,7 +89,14 @@ class Research::Hal::Publication < ApplicationRecord publication.open_access = doc.attributes['openAccess_bool'] publication.journal_title = doc.attributes['journalTitle_s'] publication.file = doc.attributes['files_s']&.first - publication.authors_list = doc.attributes['authLastNameFirstName_s'].join(', ') + publication.authors_list = doc.attributes['authFullName_s'].join(', ') + publication.authors_citeproc = [] + doc.attributes['authLastName_s'].each_with_index do |last_name, index| + publication.authors_citeproc << { + "family" => last_name, + "given" => doc.attributes['authFirstName_s'][index] + } + end publication.save publication end @@ -117,9 +126,7 @@ class Research::Hal::Publication < ApplicationRecord def to_citeproc(website: nil) { "title" => title, - "author" => authors.map { |author| - { "family" => author.last_name, "given" => author.first_name } - }, + "author" => authors_citeproc, "URL" => hal_url, "container-title" => journal_title, "pdf" => file, diff --git a/db/migrate/20230711073707_add_authors_citeproc_to_research_hal_publications.rb b/db/migrate/20230711073707_add_authors_citeproc_to_research_hal_publications.rb new file mode 100644 index 000000000..ed3c28160 --- /dev/null +++ b/db/migrate/20230711073707_add_authors_citeproc_to_research_hal_publications.rb @@ -0,0 +1,5 @@ +class AddAuthorsCiteprocToResearchHalPublications < ActiveRecord::Migration[7.0] + def change + add_column :research_hal_publications, :authors_citeproc, :json + end +end diff --git a/db/schema.rb b/db/schema.rb index 21688fd27..8d846ab19 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_07_11_071413) do +ActiveRecord::Schema[7.0].define(version: 2023_07_11_073707) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -744,6 +744,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_11_071413) do t.string "journal_title" t.text "file" t.text "authors_list" + t.json "authors_citeproc" t.index ["docid"], name: "index_research_hal_publications_on_docid" end -- GitLab