diff --git a/lib/mse25/timeline.ex b/lib/mse25/timeline.ex index 7c8da09..dae3675 100644 --- a/lib/mse25/timeline.ex +++ b/lib/mse25/timeline.ex @@ -44,6 +44,16 @@ defmodule Mse25.Timeline do Task.async(fn -> Directus.get_links!(limit: 9999, query: query) end), Task.async(fn -> Directus.get_events!(limit: 9999, query: query) end) ]) + + results = + items + |> List.flatten() + |> Enum.sort_by(&sort_key/1) + |> Enum.map(&categorize/1) + # |> Enum.group_by(fn item -> sort_key(item) |> String.slice(5..6) end) + |> Enum.reverse() + + {:ok, %{query: query, results: results, count: length(results)}} end defp sort_key(%{"pubDate" => date}), do: date diff --git a/lib/mse25_web/controllers/item_html/annual.html.heex b/lib/mse25_web/controllers/item_html/annual.html.heex index 27e9ed4..0435525 100644 --- a/lib/mse25_web/controllers/item_html/annual.html.heex +++ b/lib/mse25_web/controllers/item_html/annual.html.heex @@ -53,12 +53,14 @@

<%= item["lead"] %>

- item["poster"] <> "?key=poster"} - loading="lazy" - alt="Affisch" - width="200" - /> + <%= if item["poster"] do %> + item["poster"] <> "?key=poster"} + loading="lazy" + alt="Affisch" + width="200" + /> + <% end %> <% end %> <%= if t == :links do %>

@@ -89,13 +91,15 @@
  • <%= song["artist"]["name"] <> " - " <> song["title"] %>
  • <% end %> - item["cover"] <> "?key=rectangular"} - alt="Skivomslag" - loading="lazy" - height="75" - width="75" - /> + <%= if item["cover"] do %> + item["cover"] <> "?key=rectangular"} + alt="Skivomslag" + loading="lazy" + height="75" + width="75" + /> + <% end %> <% end %> <% end %> diff --git a/lib/mse25_web/controllers/item_html/show.html.heex b/lib/mse25_web/controllers/item_html/show.html.heex deleted file mode 100644 index 4f64043..0000000 --- a/lib/mse25_web/controllers/item_html/show.html.heex +++ /dev/null @@ -1,12 +0,0 @@ -
    -
    -<%= @published_at %> -

    <%= @heading %>

    -
    - -<%= raw @contents %> - -
    -

    Skribent: Anders Englöf Ytterström. Publicerad <%= @published_at %> och senast uppdaterad <%= @updated_at %>.

    -
    -
    diff --git a/lib/mse25_web/controllers/page_controller.ex b/lib/mse25_web/controllers/page_controller.ex index 43d3a9b..f1fde24 100644 --- a/lib/mse25_web/controllers/page_controller.ex +++ b/lib/mse25_web/controllers/page_controller.ex @@ -2,6 +2,7 @@ defmodule Mse25Web.PageController do use Mse25Web, :controller alias Mse25.Directus + alias Mse25.Timeline def home(conn, _params) do [most_recent_article, older_article] = Directus.get_articles!(limit: 2) @@ -20,6 +21,30 @@ defmodule Mse25Web.PageController do ) end + def search(conn, %{"q" => ""}) do + redirect(conn, to: ~p"/") + end + + def search(conn, %{"q" => query}) do + {:ok, %{results: results, count: count}} = Timeline.search(query) + + scount = + case count do + 0 -> "Inga" + c -> to_string(c) + end + + render(conn, :search, + q: query, + page_title: scount <> " sökresultat för \"" <> query <> "\"", + results: results + ) + end + + def search(conn, _params) do + redirect(conn, to: ~p"/") + end + def articles(conn, params) do articles = case params do diff --git a/lib/mse25_web/controllers/page_html/home.html.heex b/lib/mse25_web/controllers/page_html/home.html.heex index 4ccac82..7c70d10 100644 --- a/lib/mse25_web/controllers/page_html/home.html.heex +++ b/lib/mse25_web/controllers/page_html/home.html.heex @@ -1,6 +1,6 @@
    Anders Englöf Ytterström -
    + :
    diff --git a/lib/mse25_web/controllers/page_html/search.html.heex b/lib/mse25_web/controllers/page_html/search.html.heex new file mode 100644 index 0000000..33b9038 --- /dev/null +++ b/lib/mse25_web/controllers/page_html/search.html.heex @@ -0,0 +1,82 @@ +
    + +
    + : + + +
    +

    <%= @page_title %>

    + <%= for item = %{t: t} <- @results do %> +
    + <%= if t == :articles do %> +

    + item["slug"]}> + <%= item["title"] %> + +

    + <% end %> + <%= if t == :events do %> +

    + item["slug"]}> + <%= item["title"] %> + +

    +

    <%= item["lead"] %>

    + <%= if item["poster"] do %> + item["poster"] <> "?key=poster"} + loading="lazy" + alt="Affisch" + width="200" + /> + <% end %> + <% end %> + <%= if t == :links do %> +

    + <%= item["title"] %> +

    +

    <%= raw(Earmark.as_html!(item["contents"])) %>

    + Källa: + item["source"]}> + <%= item["h1"] %> + + <% end %> + <%= if t == :albums do %> +

    + <%= item["artist"] <> + " - " <> item["album"] <> " (" <> to_string(item["year"]) <> ")" %> + +

    + <%= if item["contents"] do %> +

    <%= raw(Earmark.as_html!(item["contents"])) %>

    + <% end %> +
      + <%= for song <- item["songs"] do %> +
    • <%= song["artist"]["name"] <> " - " <> song["title"] %>
    • + <% end %> +
    + <%= if item["cover"] do %> + item["cover"] <> "?key=rectangular"} + alt="Skivomslag" + loading="lazy" + height="75" + width="75" + /> + <% end %> + <% end %> +
    + <% end %> +
    diff --git a/lib/mse25_web/router.ex b/lib/mse25_web/router.ex index a80d74c..3e94e3c 100644 --- a/lib/mse25_web/router.ex +++ b/lib/mse25_web/router.ex @@ -18,10 +18,10 @@ defmodule Mse25Web.Router do pipe_through :browser get "/", PageController, :home - get "/evenemang", PageController, :events get "/webblogg", PageController, :articles get "/delningar", PageController, :links + get "/sok", PageController, :search # get "/kommande-evenemang.ics", EventController, :calendar # get "/event-map.js", EventController, :interactive_map