Skip to content
Snippets Groups Projects
Commit 19ba18d1 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

prepare

parent c6d49270
No related branches found
No related tags found
No related merge requests found
......@@ -60,6 +60,12 @@ module Admin::ApplicationHelper
form: form.options.dig(:html, :id)
end
def prepare_for_github(html)
sanitize html.to_s,
tags: %w(table a figure img figcaption i em b strong h2 h3 h4 h5 h6 blockquote),
attributes: %w(href alt title target rel src srcset)
end
private
def polymorphic_url_param(object_or_class, **options)
......
......@@ -58,6 +58,7 @@ class Communication::Website::Post < ApplicationRecord
end
def publish_to_github
return if published_at.nil?
github.publish kind: :posts,
file: github_file,
title: to_s,
......
......@@ -15,6 +15,7 @@ class Github
local_path = "#{ local_directory }/#{ file }"
Pathname(local_path).dirname.mkpath
File.write local_path, data
return if repository.blank?
remote_file = "_#{ kind }/#{ file }"
begin
content = client.content repository, path: remote_file
......@@ -23,7 +24,6 @@ class Github
sha = nil
end
commit_message ||= "[#{kind}] Save #{ title }"
return if repository.blank?
client.create_contents repository,
remote_file,
commit_message,
......
......@@ -3,6 +3,6 @@ title: "<%= @page.title %>"
permalink: "<%= @page.path %>"
parent: "<%= @page.parent_id %>"
description: "<%= @page.description %>"
text: "<%= @page.text %>"
text: "<%= prepare_for_github @page.text %>"
---
<%= @page.content_without_frontmatter.html_safe %>
......@@ -3,6 +3,6 @@ title: "<%= @post.title %>"
date: <%= @post.published_at %> UTC
slug: "<%= @post.slug %>"
description: "<%= @post.description %>"
text: "<%= @post.text %>"
text: "<%= prepare_for_github @post.text %>"
---
<%= @post.content_without_frontmatter.html_safe %>
......@@ -29,6 +29,10 @@
<td width="150"><%= Communication::Website::Page.human_attribute_name('slug') %></td>
<td><%= @post.slug %></td>
</tr>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('published_at') %></td>
<td><%= l @post.published_at, format: :long %></td>
</tr>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('published') %></td>
<td><%= t @post.published %></td>
......
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