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

better export

parent 6c40770e
No related branches found
No related tags found
No related merge requests found
......@@ -60,9 +60,8 @@ module Admin::ApplicationHelper
form: form.options.dig(:html, :id)
end
def prepare_for_github(html, university)
def prepare_html_for_static(html, university)
text = html.to_s
text = sanitize text,
tags: %w(table figure figcaption strong em b i u p code pre tt samp kbd var sub sup dfn cite big small address hr br span h1 h2 h3 h4 h5 h6 ul ol li dl dt dd abbr acronym a img blockquote del ins),
attributes: %w(rel href src srcset width height alt cite datetime title class name xml:lang abbr style target)
......@@ -72,6 +71,15 @@ module Admin::ApplicationHelper
sanitize text
end
def prepare_text_for_static(text)
# Beware, it works only at level one, with 2 spaces
indentation = ' '
text = strip_tags text.to_s
text.gsub! "\r\n", "\n" # Remove useless \r
text.gsub! "\n", "\n#{indentation}" # Indent properly to avoid broken frontmatter
text.chomp
end
def collection_tree(list, except = nil)
collection = []
list.root.ordered.each do |object|
......
......@@ -3,4 +3,4 @@ title: "<%= @category.name %>"
slug: "<%= @category.slug %>"
position: <%= @category.position %>
---
<%= prepare_for_github @category.description, @category.university %>
<%= prepare_html_for_static @category.description, @category.university %>
......@@ -7,6 +7,6 @@ image: "<%= @home.featured_image.blob.id %>"
image_alt: "<%= @home.featured_image_alt %>"
<% end %>
description: >
<%= strip_tags(@home.text.to_s).chomp %>
<%= prepare_text_for_static @home.text %>
---
<%= prepare_for_github @home.text, @home.university %>
<%= prepare_html_for_static @home.text, @home.university %>
......@@ -11,6 +11,6 @@ image_alt: "<%= @page.featured_image_alt %>"
category: "<%= @page.related_category.path %>/"
<% end %>
description: >
<%= prepare_for_github @page.description, @page.university %>
<%= prepare_text_for_static @page.description %>
---
<%= prepare_for_github @page.text, @page.university %>
<%= prepare_html_for_static @page.text, @page.university %>
......@@ -20,6 +20,6 @@ image: "<%= @post.featured_image.blob.id %>"
image_alt: "<%= @post.featured_image_alt %>"
<% end %>
description: >
<%= @post.description.chomp %>
<%= prepare_text_for_static @post.description %>
---
<%= prepare_for_github @post.text, @post.university %>
<%= prepare_html_for_static @post.text, @post.university %>
......@@ -3,7 +3,7 @@ title: >
<%= @program.name %>
url: /<%= @website.programs_github_directory %><%= @program.path %>/
description: >
<%= prepare_for_github @program.description, @program.university %>
<%= prepare_text_for_static @program.description %>
position: <%= @program.position %>
<% if @program.best_featured_image.attached? %>
image: "<%= @program.best_featured_image.blob.id %>"
......@@ -47,6 +47,6 @@ ects: <%= @program.ects %>
:content
].each do |property| %>
<%= property.to_s %>: >
<%= prepare_for_github @program.send("best_#{property}"), @program.university %>
<%= prepare_html_for_static @program.send("best_#{property}"), @program.university %>
<% end %>
---
---
title: "<%= @article.title %>"
description: >
<%= @article.abstract %>
<%= prepare_text_for_static @article.abstract %>
<% if @article.volume && @article.volume.path %>
volumes:
- "<%= @article.volume.path %>"
......
......@@ -2,7 +2,7 @@
title: >
<%= @journal.title %>
description: >
<%= @journal.description %>
<%= prepare_text_for_static @journal.description %>
issn: >
<%= @journal.issn %>
---
......@@ -23,4 +23,4 @@ roles:
- administrator
<% end %>
---
<%= prepare_for_github @person.biography, @person.university %>
<%= prepare_html_for_static @person.biography, @person.university %>
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