diff --git a/assets/app.css b/assets/app.css index 2f2ef1a..3d36894 100644 --- a/assets/app.css +++ b/assets/app.css @@ -199,3 +199,18 @@ section { margin-top: 3em; } } + +.brutal-legend { + display: flex; + gap: 1em; + flex-direction: row-reverse; + + > p { + flex: 1; + margin: 0; + } + + > img { + aspect-ratio: 1; + } +} diff --git a/lib/mse25/directus.ex b/lib/mse25/directus.ex index 292e039..6750852 100644 --- a/lib/mse25/directus.ex +++ b/lib/mse25/directus.ex @@ -31,12 +31,7 @@ defmodule Mse25.Directus do :albums, externalId, [ - "purchased_at", - "album", - "year", - "youtubeId", - "externalId", - "cover", + "*", "songs.title", "songs.artist.name" ] @@ -51,24 +46,19 @@ defmodule Mse25.Directus do "fields=" <> Enum.join( [ - "purchased_at", - "album", - "year", - "externalId", - "cover.filename_download", - "cover.width", - "cover.height", + "*", "songs.title", "songs.artist.name" ], "," ) ] + |> annual?(:albums, options) |> query_params_string(options, :brutal_legends) get("/albums?" <> params) - |> Enum.map(fn m = %{"songs" => [%{"artist" => %{"name" => a}} | _]} -> - Map.put(m, "artist", a) + |> Enum.map(fn m = %{"songs" => [%{"artist" => %{"name" => a}} | _], "purchased_at" => pa} -> + m |> Map.put("artist", a) |> Map.put("purchase_year", String.slice(pa, 0..3)) end) end diff --git a/lib/mse25_web/controllers/item_controller.ex b/lib/mse25_web/controllers/item_controller.ex index 7d27978..161cffc 100644 --- a/lib/mse25_web/controllers/item_controller.ex +++ b/lib/mse25_web/controllers/item_controller.ex @@ -34,6 +34,17 @@ defmodule Mse25Web.ItemController do end end + defp fetch([_year, album_id], :album) do + case Directus.get_album(album_id) do + {:ok, response} -> {:ok, :album, response} + not_found -> not_found + end + end + + defp fetch([year, "brutal-legend-" <> external_id]) do + fetch([year, external_id], :album) + end + defp fetch([year, slug]) do fetch([year, slug], :article) end @@ -147,4 +158,26 @@ defmodule Mse25Web.ItemController do updated_at: String.slice(updated_at, 0..9) ] end + + defp assigns(:album, %{ + "year" => year, + "album" => album, + "contents" => contents, + "cover" => cover, + "purchased_at" => purchased_at, + "externalId" => count, + "songs" => songs + }) do + [ + count: count, + page_title: album, + album: album, + cover: cover, + year: to_string(year), + purchase_year: String.slice(purchased_at, 0..3), + contents: Earmark.as_html!(contents), + songs: Enum.map(songs, fn %{"title" => name} -> "\"" <> name <> "\"" end), + artist: List.first(songs) |> Map.get("artist") |> Map.get("name") + ] + end end diff --git a/lib/mse25_web/controllers/item_html/album.html.heex b/lib/mse25_web/controllers/item_html/album.html.heex new file mode 100644 index 0000000..352bfd3 --- /dev/null +++ b/lib/mse25_web/controllers/item_html/album.html.heex @@ -0,0 +1,40 @@ +
+
+ +

<%= @artist <> " - " <> @album <> " (" <> @year <> ")" %>

+
+ +

+ Som jag tidigare skrivit om har jag ett roligt projekt pågående: att äga alla låtar i spelet Brütal Legend äldre än 1990 på vinyl, där det är möjligt. +

+ +
+

+ #<%= @count %>: <%= @artist %> - <%= csl(@songs) %>, från <%= @album %> (<%= @year %>) +

+ <%= if @cover do %> + @cover <> "?key=rectangular"} + alt="Skivomslag" + loading="lazy" + height="75" + width="75" + /> + <% end %> +
+ + <%= raw(@contents) %> +
diff --git a/lib/mse25_web/controllers/page_html/home.html.heex b/lib/mse25_web/controllers/page_html/home.html.heex index 939fdaa..4ccac82 100644 --- a/lib/mse25_web/controllers/page_html/home.html.heex +++ b/lib/mse25_web/controllers/page_html/home.html.heex @@ -42,7 +42,7 @@ <%= for legend <- @brutal_legends do %>
Införskaffat (<%= legend["purchased_at"] %>):
- + legend["purchase_year"] <> "/brutal-legend-" <> legend["externalId"]}> <%= legend["artist"] %> - <%= legend["album"] %> (<%= legend["year"] %>)