From 2cf8cc60a8231cc1f836c31a928fdf84bfeba613 Mon Sep 17 00:00:00 2001 From: Inhji Date: Thu, 13 Jul 2023 07:14:24 +0200 Subject: [PATCH] simplify and fix outline rendering --- lib/chiya_web/controllers/page_html.ex | 11 +++++++---- lib/chiya_web/controllers/page_html/note.html.heex | 4 +--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/chiya_web/controllers/page_html.ex b/lib/chiya_web/controllers/page_html.ex index 348679c..a2e64ec 100644 --- a/lib/chiya_web/controllers/page_html.ex +++ b/lib/chiya_web/controllers/page_html.ex @@ -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 diff --git a/lib/chiya_web/controllers/page_html/note.html.heex b/lib/chiya_web/controllers/page_html/note.html.heex index 9b7977b..e389e91 100644 --- a/lib/chiya_web/controllers/page_html/note.html.heex +++ b/lib/chiya_web/controllers/page_html/note.html.heex @@ -3,9 +3,7 @@ <%= @note.name %> - +
<%= Markdown.render(@note.content) |> raw %>