Skip to content
Snippets Groups Projects
Unverified Commit f8130a0e authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

blob handled in github file

parent 2cc89724
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,17 @@ class Communication::Website::GithubFile < ApplicationRecord
def remove_from_github
return unless github.valid?
github.remove(github_path, github_remove_commit_message)
github.remove github_path, github_remove_commit_message
remove_media_from_github
end
def remove_media_from_github
return unless about.respond_to?(:active_storage_blobs)
about.active_storage_blobs.each { |blob| remove_blob_from_github(blob) }
end
def remove_blob_from_github(blob)
github.remove github_blob_path(blob), github_blob_remove_commit_message
end
def github
......@@ -96,7 +106,7 @@ class Communication::Website::GithubFile < ApplicationRecord
def github_blob_params(blob)
blob.analyze unless blob.analyzed?
{
path: "_data/media/#{blob.id[0..1]}/#{blob.id}.yml",
path: github_blob_path(blob),
data: ApplicationController.render(
template: 'active_storage/blobs/jekyll',
layout: false,
......@@ -105,6 +115,10 @@ class Communication::Website::GithubFile < ApplicationRecord
}
end
def github_blob_path(blob)
"_data/media/#{blob.id[0..1]}/#{blob.id}.yml"
end
def github_commit_message
"[#{about.class.name.demodulize}] Save #{about.to_s}"
end
......@@ -116,4 +130,8 @@ class Communication::Website::GithubFile < ApplicationRecord
def github_remove_commit_message
"[#{about.class.name.demodulize}] Remove #{about.to_s}"
end
def github_blob_remove_commit_message(blob)
"[Medium] Remove ##{blob.id}"
end
end
......@@ -2,32 +2,11 @@ module Communication::Website::WithPublishableObjects
extend ActiveSupport::Concern
included do
def publish_about_object
# TODO: Handle Research::Journal then use the commented version.
# about.force_publish! unless about.nil?
about.force_publish! if about.is_a?(Education::School)
end
def publish_blob(blob)
return unless github.valid?
blob.analyze unless blob.analyzed?
github_path = "_data/media/#{blob.id[0..1]}/#{blob.id}.yml"
github_commit_message = "[Medium] Save ##{blob.id}"
data = ApplicationController.render(
template: 'active_storage/blobs/jekyll',
layout: false,
assigns: { blob: blob }
)
github.publish(path: github_path, commit: github_commit_message, data: data)
end
handle_asynchronously :publish_blob, queue: 'default'
def remove_blob(blob)
return unless github.valid?
github_path = "_data/media/#{blob.id[0..1]}/#{blob.id}.yml"
github_commit_message = "[Medium] Remove ##{blob.id}"
github.remove(github_path, github_commit_message)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment