chiya/lib/chiya_web/controllers/page_html.ex

24 lines
687 B
Elixir
Raw Normal View History

2023-03-05 16:07:40 +01:00
defmodule ChiyaWeb.PageHTML do
use ChiyaWeb, :html_public
2023-07-11 07:23:07 +02:00
import Phoenix.HTML.Tag, only: [content_tag: 3, content_tag: 2]
2023-03-05 16:07:40 +01:00
embed_templates "page_html/*"
2023-04-10 19:18:27 +02:00
def tag_list([]), do: "No Tags"
def tag_list(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
2023-07-11 07:23:07 +02:00
def render_outline(note) do
list = ChiyaWeb.Outline.get(note.content)
Enum.map(list, &do_render_outline/1)
end
def do_render_outline(%{text: text, children: children, level: _level}) do
content_tag(:ul, [class: "m-0"],
do: [
content_tag(:li, do: content_tag(:a, text, href: "##{Slugger.slugify_downcase(text)}")),
2023-07-11 07:23:07 +02:00
Enum.map(children, &do_render_outline/1)
]
)
end
2023-03-05 16:07:40 +01:00
end