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

category has 2 github files per website

parent 7a15450d
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,29 @@ class Communication::Website::Category < ApplicationRecord
# Override from WithGithubFiles
def github_path_generated
"_categories/#{slug}.html"
"actualites/#{slug}.html"
end
# Override from WithGithubFiles
def to_jekyll(github_file)
ApplicationController.render(
template: "admin/communication/website/categories/jekyll",
layout: false,
assigns: { category: self, github_file: github_file }
)
end
def github_manifest
super << {
identifier: "collection_item",
generated_path: "_data/categories/#{slug}.yml",
data: -> (github_file) { ApplicationController.render(
template: "admin/communication/website/categories/jekyll_collection",
formats: [:yml],
layout: false,
assigns: { category: self, github_file: github_file }
) }
}
end
protected
......
......@@ -30,7 +30,7 @@ class Communication::Website::GithubFile < ApplicationRecord
return unless github.valid?
add_to_batch(github)
if github.commit_batch(github_commit_message)
update_column :github_path, about.github_path_generated
update_column :github_path, manifest_data[:generated_path]
end
end
handle_asynchronously :publish, queue: 'default'
......@@ -52,7 +52,7 @@ class Communication::Website::GithubFile < ApplicationRecord
protected
def add_media_to_batch(github)
return unless about.respond_to?(:active_storage_blobs)
return unless manifest_data[:with_media] && about.respond_to?(:active_storage_blobs)
about.active_storage_blobs.each { |blob| add_blob_to_batch(github, blob) }
end
......@@ -67,7 +67,7 @@ class Communication::Website::GithubFile < ApplicationRecord
end
def remove_media_from_github
return unless about.respond_to?(:active_storage_blobs)
return unless manifest_data[:with_media] && about.respond_to?(:active_storage_blobs)
about.active_storage_blobs.each { |blob| remove_blob_from_github(blob) }
end
......
......@@ -30,7 +30,8 @@ module WithGithubFiles
{
identifier: "primary",
generated_path: github_path_generated,
data: -> (github_file) { to_jekyll(github_file) }
data: -> (github_file) { to_jekyll(github_file) },
has_media: true
}
]
end
......
......@@ -68,6 +68,7 @@ class Github
commit = client.create_commit repository, commit_message, new_tree[:sha], branch_sha
client.update_branch repository, default_branch, commit[:sha]
@tree = nil
true
end
def remove(path, commit_message)
......
......@@ -2,8 +2,13 @@
title: "<%= @category.name %>"
slug: "<%= @category.slug %>"
identifier: "<%= @category.id %>"
permalink: "/actualites/<%= @category.slug %>"
parent: "<%= @category.parent_id %>"
description: >
<%= prepare_for_github @category.description, @category.university %>
pagination:
enabled: true
category: <%= @category.id %>
permalink: /:num/
---
<%= @github_file.github_frontmatter.content.html_safe %>
name: <%= @category.name %>
identifier: <%= @category.id %>
link: /actualites/<%= @category.slug %>
parent: <%= @category.parent_id %>
position: <%= @category.position %>
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