summaryrefslogtreecommitdiff
path: root/lib/web/views/layout_view.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/web/views/layout_view.ex')
-rw-r--r--lib/web/views/layout_view.ex123
1 files changed, 78 insertions, 45 deletions
diff --git a/lib/web/views/layout_view.ex b/lib/web/views/layout_view.ex
index 663eccf..747740f 100644
--- a/lib/web/views/layout_view.ex
+++ b/lib/web/views/layout_view.ex
@@ -2,17 +2,27 @@ defmodule NolaWeb.LayoutView do
use NolaWeb, :view
def liquid_markdown(conn, text) do
- context_path = cond do
- conn.assigns[:chan] -> "/#{conn.assigns[:network]}/#{NolaWeb.format_chan(conn.assigns[:chan])}"
- conn.assigns[:network] -> "/#{conn.assigns[:network]}/-"
- true -> "/-"
- end
+ context_path =
+ cond do
+ conn.assigns[:chan] ->
+ "/#{conn.assigns[:network]}/#{NolaWeb.format_chan(conn.assigns[:chan])}"
+
+ conn.assigns[:network] ->
+ "/#{conn.assigns[:network]}/-"
+
+ true ->
+ "/-"
+ end
{:ok, ast} = Liquex.parse(text)
- context = Liquex.Context.new(%{
- "context_path" => context_path
- })
+
+ context =
+ Liquex.Context.new(%{
+ "context_path" => context_path
+ })
+
{content, _} = Liquex.render(ast, context)
+
content
|> to_string()
|> Earmark.as_html!()
@@ -20,21 +30,28 @@ defmodule NolaWeb.LayoutView do
end
def page_title(conn) do
- target = cond do
- conn.assigns[:chan] ->
- "#{conn.assigns.chan} @ #{conn.assigns.network}"
- conn.assigns[:network] -> conn.assigns.network
- true -> Nola.name()
- end
-
- breadcrumb_title = Enum.map(Map.get(conn.assigns, :breadcrumbs)||[], fn({title, _href}) -> title end)
-
- title = [conn.assigns[:title], breadcrumb_title, target]
- |> List.flatten()
- |> Enum.uniq()
- |> Enum.filter(fn(x) -> x end)
- |> Enum.intersperse(" / ")
- |> Enum.join()
+ target =
+ cond do
+ conn.assigns[:chan] ->
+ "#{conn.assigns.chan} @ #{conn.assigns.network}"
+
+ conn.assigns[:network] ->
+ conn.assigns.network
+
+ true ->
+ Nola.name()
+ end
+
+ breadcrumb_title =
+ Enum.map(Map.get(conn.assigns, :breadcrumbs) || [], fn {title, _href} -> title end)
+
+ title =
+ [conn.assigns[:title], breadcrumb_title, target]
+ |> List.flatten()
+ |> Enum.uniq()
+ |> Enum.filter(fn x -> x end)
+ |> Enum.intersperse(" / ")
+ |> Enum.join()
content_tag(:title, title)
end
@@ -42,14 +59,16 @@ defmodule NolaWeb.LayoutView do
def format_time(date, with_relative \\ true) do
alias Timex.Format.DateTime.Formatters
alias Timex.Timezone
- date = if is_integer(date) do
- date
- |> DateTime.from_unix!(:millisecond)
- |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase)
- else
- date
- |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase)
- end
+
+ date =
+ if is_integer(date) do
+ date
+ |> DateTime.from_unix!(:millisecond)
+ |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase)
+ else
+ date
+ |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase)
+ end
now = DateTime.now!("Europe/Paris", Tzdata.TimeZoneDatabase)
@@ -57,25 +76,39 @@ defmodule NolaWeb.LayoutView do
date_week = Timex.iso_week(date)
{y, w} = now_week
- now_last_week = {y, w-1}
- now_last_roll = 7-Timex.days_to_beginning_of_week(now)
+ now_last_week = {y, w - 1}
+ now_last_roll = 7 - Timex.days_to_beginning_of_week(now)
date_date = DateTime.to_date(date)
now_date = DateTime.to_date(date)
- format = cond do
- date.year != now.year -> "{D}/{M}/{YYYY} {h24}:{m}"
- date_date == now_date -> "{h24}:{m}"
- (now_week == date_week) || (date_week == now_last_week && (Date.day_of_week(date) >= now_last_roll)) -> "{WDfull} {h24}:{m}"
- (now.year == date.year && now.month == date.month) -> "{WDfull} {D} {h24}:{m}"
- true -> "{WDfull} {D} {M} {h24}:{m}"
- end
+ format =
+ cond do
+ date.year != now.year ->
+ "{D}/{M}/{YYYY} {h24}:{m}"
- {:ok, relative} = Formatters.Relative.relative_to(date, Timex.now("Europe/Paris"), "{relative}", "fr")
- {:ok, full} = Formatters.Default.lformat(date, "{WDfull} {D} {YYYY} {h24}:{m}", "fr") #"{h24}:{m} {WDfull} {D}", "fr")
- {:ok, detail} = Formatters.Default.lformat(date, format, "fr") #"{h24}:{m} {WDfull} {D}", "fr")
+ date_date == now_date ->
+ "{h24}:{m}"
- content_tag(:time, if(with_relative, do: relative, else: detail), [title: full])
- end
+ now_week == date_week ||
+ (date_week == now_last_week && Date.day_of_week(date) >= now_last_roll) ->
+ "{WDfull} {h24}:{m}"
+
+ now.year == date.year && now.month == date.month ->
+ "{WDfull} {D} {h24}:{m}"
+ true ->
+ "{WDfull} {D} {M} {h24}:{m}"
+ end
+
+ {:ok, relative} =
+ Formatters.Relative.relative_to(date, Timex.now("Europe/Paris"), "{relative}", "fr")
+
+ # "{h24}:{m} {WDfull} {D}", "fr")
+ {:ok, full} = Formatters.Default.lformat(date, "{WDfull} {D} {YYYY} {h24}:{m}", "fr")
+ # "{h24}:{m} {WDfull} {D}", "fr")
+ {:ok, detail} = Formatters.Default.lformat(date, format, "fr")
+
+ content_tag(:time, if(with_relative, do: relative, else: detail), title: full)
+ end
end