From 403fc9d5cbd516ea4e93e0e10292ee2c652b129d Mon Sep 17 00:00:00 2001 From: Raymonzut <40148684+Raymonzut@users.noreply.github.com> Date: Fri, 6 Nov 2020 22:38:10 +0100 Subject: [PATCH] Account for multiple years for sorting posts - Prepare for 2021 --- client/public/gen.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/public/gen.ex b/client/public/gen.ex index f124480..5d72c1b 100644 --- a/client/public/gen.ex +++ b/client/public/gen.ex @@ -37,7 +37,8 @@ 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) # Group by month |> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(8..15) end) - |> Enum.sort_by(fn {d, _c} -> Enum.find_index(months, &(&1 == String.slice(d, 0..2))) end) + |> Enum.sort_by(fn {d, _c} -> (length months) * elem(Integer.parse(String.slice(d, 4..7)), 0) + + Enum.find_index(months, &(&1 == String.slice(d, 0..2))) end) |> Enum.reverse() |> Enum.map(fn {month, posts} -> "\n

" <> month <> "

\n" <> (posts |> Enum.map(fn post -> "

" <> (Map.get(post, :date) |> String.slice(0..6)) <>