simplify and fix outline rendering
This commit is contained in:
parent
f41f663e83
commit
2cf8cc60a8
2 changed files with 8 additions and 7 deletions
|
@ -8,16 +8,19 @@ defmodule ChiyaWeb.PageHTML do
|
||||||
def tag_list(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
|
def tag_list(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
|
||||||
|
|
||||||
def render_outline(note) do
|
def render_outline(note) do
|
||||||
list = ChiyaWeb.Outline.get(note.content)
|
note.content
|
||||||
Enum.map(list, &do_render_outline/1)
|
|> ChiyaWeb.Outline.get()
|
||||||
|
|> Enum.map(&do_render_outline/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_render_outline(%{text: text, children: children, level: _level}) do
|
def do_render_outline(%{text: text, children: children, level: _level}) do
|
||||||
|
slug = Slugger.slugify_downcase(text)
|
||||||
content_tag(:ul, [class: "m-0"],
|
content_tag(:ul, [class: "m-0"],
|
||||||
do: [
|
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)
|
Enum.map(children, &do_render_outline/1)
|
||||||
]
|
]
|
||||||
)
|
) |> safe_to_string()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
<%= @note.name %>
|
<%= @note.name %>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<aside class="max-w-2xl mx-auto mt-8 prose prose-gruvbox bg-theme-background1 rounded p-2 empty:hidden">
|
<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>
|
||||||
<%= raw Enum.map(render_outline(@note), &safe_to_string/1) %>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<section class="mt-8 mx-auto prose prose-gruvbox md:prose-lg lg:prose-xl | p-summary e-content">
|
<section class="mt-8 mx-auto prose prose-gruvbox md:prose-lg lg:prose-xl | p-summary e-content">
|
||||||
<%= Markdown.render(@note.content) |> raw %>
|
<%= Markdown.render(@note.content) |> raw %>
|
||||||
|
|
Loading…
Reference in a new issue