Group posts by year

master
Raymon Zutekouw 11 months ago
parent 2c1a718d5c
commit 71e0772682
Signed by: raymon
GPG Key ID: 0E62222846283925
  1. 26
      client/gen.exs
  2. 6
      client/public/assets/styling/general.css

@ -63,6 +63,13 @@ constructLocalPath = fn p -> dateFolder.(p) <> normalize_title.(Map.get(p, :titl
post_contents = post_contents_org
|> Enum.map(fn postMap -> Map.merge(postMap, %{localpath: (constructLocalPath.(postMap))}) end)
date_sort = fn post ->
date = Map.get(post, :date)
month = Enum.find_index(months, &(&1 == String.slice(date, 8..10)))
day = elem(Integer.parse(String.slice(date, 5..6)), 0)
32 * month + day
end
index_file =
post_contents
|> Enum.sort_by(
@ -71,15 +78,18 @@ index_file =
|> Integer.parse())
)
|> Enum.reverse()
# Group by month
|> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(8..15) 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)
# Group by year
|> Enum.group_by(fn m -> Map.get(m, :date) |> String.slice(12..15) end)
|> Enum.sort_by(fn {d, _c} -> Integer.parse(d) end)
|> Enum.reverse()
|> Enum.map(fn {month, posts} -> "\n<h1>" <> month <> "</h1>\n" <> (posts |>
Enum.map(fn post -> "<h2 class=\"post-link\">" <> (Map.get(post, :date) |> String.slice(0..6)) <>
" - <a href=\"" <> Map.get(post, :localpath) <> ".html\">" <> Map.get(post, :title) <> "</a></h2>"
end) |> Enum.join("\n")) end)
|> Enum.join("\n")
|> Enum.map(fn {year, posts} -> "\n<h1>" <> year <> "</h1>\n<ul>" <> (posts |> Enum.sort_by(date_sort) |> Enum.reverse() |>
Enum.map(fn post -> "<li class=\"post-link\">" <>
"<time datetime=\""<> Map.get(post, :date) <> "\">" <> (Map.get(post, :date) |> String.slice(0..10)) <> "</time>" <>
" - " <>
"<a href=\"" <> Map.get(post, :localpath) <> ".html\">" <> Map.get(post, :title) <> "</a>" <>
"</li>"
end) |> Enum.join("\n")) end)
|> Enum.join("\n</ul>")
|> (fn v -> %{index: v} end).()
|> fill_template_pretemplated.(index_template).()

@ -47,11 +47,9 @@ h1 {
font-size: 2.0em;
}
h2 {
font-size: 1.25em;
}
.post-link {
font-family: monospace;
font-size: 1.25em;
margin: auto 0;
}

Loading…
Cancel
Save