diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index c0e919996984eaae764d8b56a08079de868c0d5d..7b1322bf7cf753cd1824f47dec945b088f0ecf51 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -33,6 +33,10 @@ class Research::Journal::Volume < ApplicationRecord scope :ordered, -> { order(number: :desc, published_at: :desc) } + def cover_path + "/assets/img/volumes/#{id}#{cover.filename.extension_with_delimiter}" + end + def to_s "##{ number } #{ title }" end @@ -48,6 +52,7 @@ class Research::Journal::Volume < ApplicationRecord layout: false, assigns: { volume: self } ) + github.send_file cover, cover_path if cover.attached? end def github diff --git a/app/services/github.rb b/app/services/github.rb index a2174cc173da97719ad30ba54b2fe6afc94cf1c9..0f35bb9412aa15fd34fdd693fb6d067ccf8d8ab8 100644 --- a/app/services/github.rb +++ b/app/services/github.rb @@ -32,6 +32,26 @@ class Github rescue end + def send_file(attachment, path) + begin + content = client.content repository, path: path + sha = content[:sha] + rescue + sha = nil + end + commit_message ||= "[file] Save #{ path }" + return if repository.blank? + path_without_slash = path[1..-1] + # local_path = attachment.download_blob_to_tempfile + client.create_contents repository, + path_without_slash, + commit_message, + attachment.download, + # file: local_path, + sha: sha + rescue + end + def read_file_at(path) data = client.content repository, path: path Base64.decode64 data.content diff --git a/app/views/admin/research/journal/volumes/jekyll.html.erb b/app/views/admin/research/journal/volumes/jekyll.html.erb index b8cda39d11cdd99764c07b335528e07814d12093..50a3c146da8f2272f8f92460b7c20ea2c95d8a15 100644 --- a/app/views/admin/research/journal/volumes/jekyll.html.erb +++ b/app/views/admin/research/journal/volumes/jekyll.html.erb @@ -10,7 +10,7 @@ tags: - "economic growth" lang: Français date: "<%= @volume.published_at %>" -image: /assets/img/volume-1.png +image: "<%= @volume.cover_path %>" articles: <% @volume.articles.each do |article| %> - <%= article.id %>