From b3fe972d0e0ac0a9e1a64d93e6edd5ba40544e2b Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Tue, 23 Nov 2021 12:07:02 +0100 Subject: [PATCH] Move `\n` -> paragraphs out of fill_template - As it should only be done for the custom format --- client/gen.exs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/client/gen.exs b/client/gen.exs index 116224e..c9d7c31 100644 --- a/client/gen.exs +++ b/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 -> ("

" <> paragraph <> "

\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 -> "

" <> paragraph <> "

" 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 ->