|
|
@ -67,10 +67,21 @@ post_contents_org = |
|
|
|
end)) |
|
|
|
end)) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dateFolder = fn p -> |
|
|
|
|
|
|
|
Map.get(p, :date) |
|
|
|
|
|
|
|
|> String.slice(8..15) |
|
|
|
|
|
|
|
|> String.split(" ") |
|
|
|
|
|
|
|
|> (fn ([month, year]) -> year <> "/" <> Integer.to_string(Enum.find_index(months, &(&1 == month)) + 1) <> "/" end).() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
normalize_title = fn title -> String.replace(String.downcase(title), " ", "-") end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructLocalPath = fn p -> dateFolder.(p) <> normalize_title.(Map.get(p, :title)) end |
|
|
|
|
|
|
|
|
|
|
|
post_contents = Enum.concat(post_contents_custom, post_contents_org) |
|
|
|
post_contents = Enum.concat(post_contents_custom, post_contents_org) |
|
|
|
|
|
|
|
|> Enum.map(fn postMap -> Map.merge(postMap, %{localpath: (constructLocalPath.(postMap))}) end) |
|
|
|
|
|
|
|
|
|
|
|
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] |
|
|
|
|
|
|
|
index_file = post_contents |
|
|
|
index_file = post_contents |
|
|
|
|> Enum.sort_by(fn m -> Map.get(m, :date) |> (fn d -> Enum.find_index(months, &(&1 == String.slice(d, 8..10))) end).() end) |
|
|
|
|> Enum.sort_by(fn m -> Map.get(m, :date) |> (fn d -> Enum.find_index(months, &(&1 == String.slice(d, 8..10))) end).() end) |
|
|
|
|> Enum.reverse() |
|
|
|
|> Enum.reverse() |
|
|
@ -80,7 +91,7 @@ index_file = post_contents |
|
|
|
|> Enum.reverse() |
|
|
|
|> Enum.reverse() |
|
|
|
|> Enum.map(fn {month, posts} -> "\n<h1>" <> month <> "</h1>\n" <> (posts |> |
|
|
|
|> Enum.map(fn {month, posts} -> "\n<h1>" <> month <> "</h1>\n" <> (posts |> |
|
|
|
Enum.map(fn post -> "<h2>" <> (Map.get(post, :date) |> String.slice(0..6)) <> |
|
|
|
Enum.map(fn post -> "<h2>" <> (Map.get(post, :date) |> String.slice(0..6)) <> |
|
|
|
" - <a href=\"" <> Map.get(post, :id) <> ".html\">" <> Map.get(post, :title) <> "</a></h2>" |
|
|
|
" - <a href=\"" <> Map.get(post, :localpath) <> ".html\">" <> Map.get(post, :title) <> "</a></h2>" |
|
|
|
end) |> Enum.join("\n")) end) |
|
|
|
end) |> Enum.join("\n")) end) |
|
|
|
|> Enum.join("\n") |
|
|
|
|> Enum.join("\n") |
|
|
|
|> (fn v -> %{index: v} end).() |
|
|
|
|> (fn v -> %{index: v} end).() |
|
|
@ -90,9 +101,17 @@ File.open!("./public/gen/index.html", [:write]) |
|
|
|
|> IO.binwrite(index_file) |
|
|
|
|> IO.binwrite(index_file) |
|
|
|
|> File.close() |
|
|
|
|> File.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepare_path = fn path -> |
|
|
|
|
|
|
|
File.mkdir_p!(Path.dirname(path)) |
|
|
|
|
|
|
|
path |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
post_contents |
|
|
|
post_contents |
|
|
|
|> Enum.each(fn post -> |
|
|
|
|> Enum.each(fn post -> post |
|
|
|
File.open!("./public/gen/" <> Map.get(post, :id) <> ".html", [:write]) |
|
|
|
|> (fn p -> "./public/gen/" <> Map.get(p, :localpath) <> ".html" end).() |
|
|
|
|
|
|
|
|> prepare_path.() |
|
|
|
|
|
|
|
|> File.open!([:write]) |
|
|
|
|> IO.binwrite(fill_template.(post_template, post)) |
|
|
|
|> IO.binwrite(fill_template.(post_template, post)) |
|
|
|
|> File.close() |
|
|
|
|> File.close() |
|
|
|
end) |
|
|
|
end) |
|
|
|