2024-09-04 10:12:36 +02:00
|
|
|
defmodule Mse25Web.PageController do
|
|
|
|
|
use Mse25Web, :controller
|
|
|
|
|
|
2024-10-01 16:44:34 +02:00
|
|
|
alias Mse25.Directus
|
2024-10-05 00:36:03 +02:00
|
|
|
alias Mse25.Timeline
|
2024-10-01 16:44:34 +02:00
|
|
|
|
2024-10-07 23:44:22 +02:00
|
|
|
@almost_infinity 9999
|
|
|
|
|
|
2024-09-04 10:12:36 +02:00
|
|
|
def home(conn, _params) do
|
2025-05-01 19:30:12 +02:00
|
|
|
render(conn, :home,
|
|
|
|
|
page_title: "Anders Englöf Ytterström",
|
|
|
|
|
layout: false,
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def aio(conn, _params) do
|
2024-10-01 16:44:34 +02:00
|
|
|
[most_recent_article, older_article] = Directus.get_articles!(limit: 2)
|
2025-02-11 13:15:43 +01:00
|
|
|
recent_event = Directus.get_events!(limit: 3)
|
|
|
|
|
upcoming_events = Directus.get_events!(limit: 3, upcoming: true)
|
|
|
|
|
brutal_legends = Directus.get_albums!(limit: 8)
|
2024-10-01 16:44:34 +02:00
|
|
|
|
2025-05-01 19:30:12 +02:00
|
|
|
render(conn, :aio,
|
2024-10-03 14:38:56 +02:00
|
|
|
page_title: "Anders Englöf Ytterström",
|
2024-10-01 16:44:34 +02:00
|
|
|
layout: false,
|
|
|
|
|
recent_article: most_recent_article,
|
|
|
|
|
older_article: older_article,
|
|
|
|
|
recent_event: recent_event,
|
2024-10-03 09:55:44 +02:00
|
|
|
upcoming: upcoming_events,
|
|
|
|
|
brutal_legends: brutal_legends
|
2024-10-01 16:44:34 +02:00
|
|
|
)
|
2024-09-04 10:12:36 +02:00
|
|
|
end
|
2024-10-03 09:38:07 +02:00
|
|
|
|
2024-10-05 00:36:03 +02:00
|
|
|
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,
|
2024-10-16 15:40:53 +02:00
|
|
|
breadcrumbs: [],
|
2024-10-05 00:36:03 +02:00
|
|
|
page_title: scount <> " sökresultat för \"" <> query <> "\"",
|
|
|
|
|
results: results
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def search(conn, _params) do
|
|
|
|
|
redirect(conn, to: ~p"/")
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-03 22:52:40 +02:00
|
|
|
def articles(conn, params) do
|
2024-10-16 15:40:53 +02:00
|
|
|
{articles, page_title} =
|
2024-10-03 22:52:40 +02:00
|
|
|
case params do
|
2024-10-07 23:44:22 +02:00
|
|
|
%{"q" => query_string} ->
|
2024-10-16 15:40:53 +02:00
|
|
|
{Directus.get_articles!(limit: @almost_infinity, query: query_string),
|
|
|
|
|
"Webblogg: \"#{query_string}\""}
|
2024-10-07 23:44:22 +02:00
|
|
|
|
|
|
|
|
_ ->
|
2024-10-16 15:40:53 +02:00
|
|
|
{Directus.get_articles!(limit: @almost_infinity), "Webblogg"}
|
2024-10-03 15:31:19 +02:00
|
|
|
end
|
2024-10-03 09:38:07 +02:00
|
|
|
|
|
|
|
|
render(conn, :articles,
|
2024-10-16 15:40:53 +02:00
|
|
|
page_title: page_title,
|
2024-10-18 09:30:28 +02:00
|
|
|
breadcrumbs: [],
|
2024-10-16 15:40:53 +02:00
|
|
|
articles: group_annually(articles),
|
2024-10-03 22:52:40 +02:00
|
|
|
q: params["q"],
|
|
|
|
|
nosearch?: params["q"] == nil or params["q"] == ""
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2025-02-11 13:15:43 +01:00
|
|
|
def notes(conn, params) do
|
|
|
|
|
{notes, page_title} =
|
|
|
|
|
case params do
|
|
|
|
|
%{"q" => query_string} ->
|
|
|
|
|
{Directus.get_notes!(limit: @almost_infinity, query: query_string),
|
|
|
|
|
"Anteckningar: \"#{query_string}\""}
|
|
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
|
{Directus.get_notes!(limit: @almost_infinity), "Anteckningar"}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
render(conn, :notes,
|
|
|
|
|
page_title: page_title,
|
|
|
|
|
breadcrumbs: [],
|
|
|
|
|
notes: group_by_creation_date(notes),
|
|
|
|
|
q: params["q"],
|
|
|
|
|
nosearch?: params["q"] == nil or params["q"] == ""
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-03 22:52:40 +02:00
|
|
|
def events(conn, params) do
|
|
|
|
|
{_, %{"title" => title, "contents" => contents}} = Directus.get_page("evenemang")
|
|
|
|
|
|
|
|
|
|
events =
|
|
|
|
|
case params do
|
2024-10-07 23:44:22 +02:00
|
|
|
%{"q" => query_string} ->
|
|
|
|
|
Directus.get_events!(limit: @almost_infinity, query: query_string)
|
|
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
|
Directus.get_events!(limit: @almost_infinity)
|
2024-10-03 22:52:40 +02:00
|
|
|
end
|
|
|
|
|
|> group_annually
|
|
|
|
|
|
|
|
|
|
render(conn, :events,
|
|
|
|
|
page_title: title,
|
2024-10-16 15:40:53 +02:00
|
|
|
breadcrumbs: [],
|
|
|
|
|
show_interactive_event_map?: true,
|
2024-10-03 22:52:40 +02:00
|
|
|
contents: Earmark.as_html!(contents),
|
|
|
|
|
events: events,
|
|
|
|
|
q: params["q"],
|
|
|
|
|
nosearch?: params["q"] == nil or params["q"] == ""
|
2024-10-03 09:38:07 +02:00
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-03 14:38:56 +02:00
|
|
|
def links(conn, _params) do
|
2025-02-11 13:15:43 +01:00
|
|
|
links = Directus.get_links!(limit: @almost_infinity) |> group_by_pub_date
|
2024-10-03 14:38:56 +02:00
|
|
|
|
|
|
|
|
render(conn, :links,
|
|
|
|
|
page_title: "Delningar",
|
2024-10-16 15:40:53 +02:00
|
|
|
breadcrumbs: [],
|
2024-10-03 14:38:56 +02:00
|
|
|
links: links
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-03 09:38:07 +02:00
|
|
|
defp group_annually(items) do
|
|
|
|
|
items
|
|
|
|
|
|> Enum.group_by(fn %{"slug" => slug} -> String.slice(slug, 0..3) end)
|
|
|
|
|
|> Map.to_list()
|
|
|
|
|
|> Enum.sort(fn {a, _a}, {b, _b} -> b < a end)
|
|
|
|
|
end
|
2024-10-03 14:38:56 +02:00
|
|
|
|
2025-02-11 13:15:43 +01:00
|
|
|
defp group_by_pub_date(items) do
|
2024-10-03 14:38:56 +02:00
|
|
|
items
|
|
|
|
|
|> Enum.group_by(fn %{"pubDate" => pub_date} -> pub_date end)
|
|
|
|
|
|> Map.to_list()
|
|
|
|
|
|> Enum.sort(fn {a, _a}, {b, _b} -> b < a end)
|
|
|
|
|
end
|
2025-02-11 13:15:43 +01:00
|
|
|
|
|
|
|
|
defp group_by_creation_date(items) do
|
|
|
|
|
items
|
|
|
|
|
|> Enum.group_by(fn %{"date_created" => pub_date} -> String.slice(pub_date, 0..9) end)
|
|
|
|
|
|> Map.to_list()
|
|
|
|
|
|> Enum.sort(fn {a, _a}, {b, _b} -> b < a end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# redirect routes
|
|
|
|
|
|
|
|
|
|
def cv(conn, _params) do
|
|
|
|
|
redirect(conn, to: ~p"/cv/anders-englof-ytterstrom.html")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def brutal_legend(conn, _params) do
|
|
|
|
|
redirect(conn, to: ~p"/bl/index.html")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def mugshot(conn, _params) do
|
|
|
|
|
redirect(conn, to: ~p"/images/mugshot.jpg")
|
|
|
|
|
end
|
2024-09-04 10:12:36 +02:00
|
|
|
end
|