From fd1eba16f612fd3b2bac2ec3cde60ca18e3dd614 Mon Sep 17 00:00:00 2001 From: Inhji Date: Wed, 19 Jul 2023 22:40:32 +0200 Subject: [PATCH] fix outline --- lib/chiya_web/controllers/page_html.ex | 9 +++++++++ lib/chiya_web/controllers/page_html/note.html.heex | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/chiya_web/controllers/page_html.ex b/lib/chiya_web/controllers/page_html.ex index 7bd619c..cde8cf0 100644 --- a/lib/chiya_web/controllers/page_html.ex +++ b/lib/chiya_web/controllers/page_html.ex @@ -14,6 +14,15 @@ defmodule ChiyaWeb.PageHTML do |> Enum.map(&safe_to_string/1) end + def has_outline?(note) do + outline_empty = + note.content + |> ChiyaWeb.Outline.get() + |> Enum.empty?() + + !outline_empty + end + def do_render_outline(%{text: text, children: children, level: _level}) do slug = Slugger.slugify_downcase(text) diff --git a/lib/chiya_web/controllers/page_html/note.html.heex b/lib/chiya_web/controllers/page_html/note.html.heex index e8510ea..e2b568e 100644 --- a/lib/chiya_web/controllers/page_html/note.html.heex +++ b/lib/chiya_web/controllers/page_html/note.html.heex @@ -3,11 +3,13 @@ <%= @note.name %> + <%= if has_outline?(@note) do %> + <% end %>
<%= Markdown.render(@note.content) |> raw %>