simplify and fix outline rendering

This commit is contained in:
Inhji 2023-07-13 07:14:24 +02:00
parent f41f663e83
commit 2cf8cc60a8
2 changed files with 8 additions and 7 deletions

View file

@ -8,16 +8,19 @@ defmodule ChiyaWeb.PageHTML do
def tag_list(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
def render_outline(note) do
list = ChiyaWeb.Outline.get(note.content)
Enum.map(list, &do_render_outline/1)
note.content
|> ChiyaWeb.Outline.get()
|> Enum.map(&do_render_outline/1)
end
def do_render_outline(%{text: text, children: children, level: _level}) do
slug = Slugger.slugify_downcase(text)
content_tag(:ul, [class: "m-0"],
do: [
content_tag(:li, do: content_tag(:a, text, href: "##{Slugger.slugify_downcase(text)}")),
content_tag(:li, do:
content_tag(:a, text, href: "##{slug}")),
Enum.map(children, &do_render_outline/1)
]
)
) |> safe_to_string()
end
end

View file

@ -3,9 +3,7 @@
<%= @note.name %>
</.header>
<aside class="max-w-2xl mx-auto mt-8 prose prose-gruvbox bg-theme-background1 rounded p-2 empty:hidden">
<%= raw Enum.map(render_outline(@note), &safe_to_string/1) %>
</aside>
<aside class="max-w-2xl mx-auto mt-8 prose prose-gruvbox bg-theme-background1 rounded p-2 empty:hidden"><%= raw render_outline(@note) %></aside>
<section class="mt-8 mx-auto prose prose-gruvbox md:prose-lg lg:prose-xl | p-summary e-content">
<%= Markdown.render(@note.content) |> raw %>