From 4cebaf550bc1316cba5d0971240029ee6d536a2a Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Thu, 18 Nov 2021 20:33:17 +0100 Subject: [PATCH] Folder by year/month instead of id under one folder --- client/gen.exs | 27 +++++++++++++++++++++++---- client/templates/post_item.xml | 4 ++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/client/gen.exs b/client/gen.exs index 9337a62..f5f50a5 100644 --- a/client/gen.exs +++ b/client/gen.exs @@ -67,10 +67,21 @@ post_contents_org = 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) + |> 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 |> 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() @@ -80,7 +91,7 @@ index_file = post_contents |> Enum.reverse() |> Enum.map(fn {month, posts} -> "\n