# Templates will be filled by posts index_template = File.read!("./templates/index.html") post_template = File.read!("./templates/post.html") post_contents = File.ls!("./posts") |> Enum.reject(fn(x) -> String.starts_with?(x, ".") end) |> Enum.map(fn f -> File.read!("./posts/" <> f) end) |> Enum.map(fn c -> String.split(c, "\n") end) |> Enum.map(fn c -> Enum.reject(c, fn(x) -> x == "" end) end) |> Enum.map(fn c -> Enum.chunk_every(c, 2) end) |> Enum.map(fn c -> Enum.map(c, fn [k, v] -> %{String.to_atom(k) => v} end) |> Enum.reduce(%{}, fn(x, acc) -> Map.merge(x, acc) end) end) index_file = post_contents |> Enum.sort_by(fn m -> Map.get(m, :date) end) |> Enum.reverse() # Group by month |> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(0..6) end) |> Enum.reverse() |> Enum.map(fn {month, posts} -> "\n
" <> paragraph <> "
\n") end) |> Enum.join("") end end)) |> File.close() end)