Move `\n` -> paragraphs out of fill_template

- As it should only be done for the custom format
master
Raymon Zutekouw 3 years ago
parent 266b6e0733
commit b3fe972d0e
No known key found for this signature in database
GPG Key ID: 1E9BCC39EDD1DD53
  1. 17
      client/gen.exs

@ -8,19 +8,17 @@ post_feed_template = File.read!("./templates/posts.xml")
# Converting handlebars in template to values
fill_template = fn template, pairs ->
Regex.compile!("{{(.*)}}") |>
Regex.replace(template, fn _, key -> if key != "content" do Map.get(pairs, String.to_atom(key)) else
Map.get(pairs, String.to_atom(key))
# Converting \n to paragraphs
|> String.split("\\n")
|> Enum.reject(fn(x) -> x == "" end)
|> Enum.map(fn paragraph -> ("<p>" <> paragraph <> "</p>\n") end)
|> Enum.join("")
end
end)
Regex.replace(template, fn _, key -> Map.get(pairs, String.to_atom(key)) end)
end
fill_template_pretemplated = fn template -> &fill_template.(template, &1) end
wrapInParagraphs = fn content -> content
|> String.split("\\n")
|> Enum.reject(fn(x) -> x == "" end)
|> Enum.map(fn paragraph -> "<p>" <> paragraph <> "</p>" end)
|> Enum.join("")
end
post_contents_custom = File.ls!("./posts_custom")
|> Enum.reject(fn(x) -> String.starts_with?(x, ".") end)
|> Enum.map(fn f -> File.read!("./posts_custom/" <> f) end)
@ -31,6 +29,7 @@ post_contents_custom = File.ls!("./posts_custom")
Enum.map(c, fn [k, v] -> %{String.to_atom(k) => v} end)
|> Enum.reduce(%{}, fn(x, acc) -> Map.merge(x, acc) end)
end)
|> Enum.map(fn m -> Map.update!(m, :content, wrapInParagraphs) end)
filterCutFileExtension = fn files ->
fn ext ->

Loading…
Cancel
Save