devel #307
6 changed files with 86 additions and 62 deletions
|
@ -47,8 +47,8 @@
|
||||||
@apply flex md:flex-row lg:flex-col mb-6 lg:mb-0;
|
@apply flex md:flex-row lg:flex-col mb-6 lg:mb-0;
|
||||||
}
|
}
|
||||||
|
|
||||||
& .menu {
|
& ul.menu {
|
||||||
@apply flex-1;
|
@apply m-0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,16 @@ defmodule Chiya.Notes.Note do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def note_excerpt(note_content) do
|
||||||
|
if String.contains?(note_content, "<!-- more -->") do
|
||||||
|
note_content
|
||||||
|
|> String.split("<!-- more -->")
|
||||||
|
|> List.first()
|
||||||
|
else
|
||||||
|
String.slice(note_content, 0..150) <> ".."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def changeset(note, attrs) do
|
def changeset(note, attrs) do
|
||||||
# if you need to have a preloaded note here,
|
# if you need to have a preloaded note here,
|
||||||
|
|
|
@ -72,11 +72,9 @@
|
||||||
|
|
||||||
<main id="site-content" class="container print:hidden">
|
<main id="site-content" class="container print:hidden">
|
||||||
<aside id="primary-sidebar">
|
<aside id="primary-sidebar">
|
||||||
<nav class="prose">
|
<nav class="prose max-w-none">
|
||||||
<div class="menu">
|
<h3>Channels</h3>
|
||||||
<strong>Channels</strong>
|
<ul class="menu">
|
||||||
|
|
||||||
<ul>
|
|
||||||
<%= for channel <- @channels do %>
|
<%= for channel <- @channels do %>
|
||||||
<li>
|
<li>
|
||||||
<a href={~p"/channel/#{channel.slug}"}>
|
<a href={~p"/channel/#{channel.slug}"}>
|
||||||
|
@ -85,17 +83,13 @@
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="menu">
|
<h3>Elsewhere</h3>
|
||||||
<strong>Elsewhere</strong>
|
<ul class="menu">
|
||||||
|
|
||||||
<ul>
|
|
||||||
<%= for identity <- @public_identities do %>
|
<%= for identity <- @public_identities do %>
|
||||||
<li><a href={identity.url}><%= identity.name %></a></li>
|
<li><a href={identity.url}><%= identity.name %></a></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
|
||||||
</nav>
|
</nav>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
defmodule ChiyaWeb.PageHTML do
|
defmodule ChiyaWeb.PageHTML do
|
||||||
use ChiyaWeb, :html_public
|
use ChiyaWeb, :html_public
|
||||||
import Phoenix.HTML.Tag, only: [content_tag: 3, content_tag: 2]
|
|
||||||
import ChiyaWeb.Format, only: [pretty_datetime: 1, pretty_date: 1, datetime: 1]
|
import ChiyaWeb.Format, only: [pretty_datetime: 1, pretty_date: 1, datetime: 1]
|
||||||
|
|
||||||
embed_templates "page_html/*"
|
embed_templates "page_html/*"
|
||||||
|
@ -27,30 +26,11 @@ defmodule ChiyaWeb.PageHTML do
|
||||||
def tag_list(assigns)
|
def tag_list(assigns)
|
||||||
|
|
||||||
def render_outline(note) do
|
def render_outline(note) do
|
||||||
note.content
|
ChiyaWeb.OutlineRenderer.render_outline(note.content)
|
||||||
|> ChiyaWeb.Outline.get()
|
|
||||||
|> Enum.map(&do_render_outline/1)
|
|
||||||
|> Enum.map(&safe_to_string/1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_outline?(note) do
|
def has_outline?(note) do
|
||||||
outline_empty =
|
ChiyaWeb.OutlineRenderer.has_outline?(note.content)
|
||||||
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)
|
|
||||||
|
|
||||||
content_tag(:ul, [class: "m-0"],
|
|
||||||
do: [
|
|
||||||
content_tag(:li, do: content_tag(:a, text, href: "##{slug}")),
|
|
||||||
Enum.map(children, &do_render_outline/1)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_tags(notes) do
|
def group_tags(notes) do
|
||||||
|
|
|
@ -1,28 +1,30 @@
|
||||||
<section class="note-list default stack">
|
<section class="note-list default stack">
|
||||||
<%= for note <- assigns.notes do %>
|
<%= for note <- assigns.notes do %>
|
||||||
<article>
|
<article class="prose max-w-none">
|
||||||
<a href={~p"/note/#{note.slug}"} class="block">
|
|
||||||
<header class="flex flex-row items-center gap-1">
|
<header class="flex flex-row items-center gap-1">
|
||||||
<span class="text-theme-primary text-lg font-semibold leading-8 flex-1">
|
<span class="text-theme-primary text-lg font-semibold leading-8 flex-1">
|
||||||
|
<a href={~p"/note/#{note.slug}"}>
|
||||||
<%= note.name %>
|
<%= note.name %>
|
||||||
</span>
|
</a>
|
||||||
<span class="text-theme-base/75 text-sm">
|
|
||||||
<%= pretty_date(note.published_at) %>
|
|
||||||
</span>
|
</span>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<%= if assigns.show_content do %>
|
<%= if assigns.show_content do %>
|
||||||
<p class="text-theme-base">
|
<p class="text-theme-base mb-3">
|
||||||
<%= String.slice(note.content, 0..150) %>
|
<%= Chiya.Notes.Note.note_excerpt(note.content) %>
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<footer class="flex">
|
||||||
|
<span class="text-theme-base/75 flex-1">
|
||||||
|
<%= pretty_date(note.published_at) %>
|
||||||
|
</span>
|
||||||
<%= if not Enum.empty?(note.tags) do %>
|
<%= if not Enum.empty?(note.tags) do %>
|
||||||
<span class="inline-block">
|
<span class="inline-block">
|
||||||
<.tag_list note={note} linked={false} />
|
<.tag_list note={note} linked={false} />
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</a>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
<% end %>
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|
38
lib/chiya_web/outline_renderer.ex
Normal file
38
lib/chiya_web/outline_renderer.ex
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
defmodule ChiyaWeb.OutlineRenderer do
|
||||||
|
import Phoenix.HTML, only: [safe_to_string: 1]
|
||||||
|
import Phoenix.HTML.Tag, only: [content_tag: 3, content_tag: 2]
|
||||||
|
|
||||||
|
def render_outline(content) do
|
||||||
|
children =
|
||||||
|
content
|
||||||
|
|> ChiyaWeb.Outline.get()
|
||||||
|
|> Enum.map(&do_render_outline/1)
|
||||||
|
|
||||||
|
root = content_tag(:ul, do: children)
|
||||||
|
|
||||||
|
safe_to_string(root)
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_outline?(content) do
|
||||||
|
outline_empty =
|
||||||
|
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)
|
||||||
|
list_item = content_tag(:li, do: content_tag(:a, text, href: "##{slug}"))
|
||||||
|
|
||||||
|
if Enum.empty?(children) do
|
||||||
|
[list_item]
|
||||||
|
else
|
||||||
|
[
|
||||||
|
list_item,
|
||||||
|
content_tag(:ul, do: Enum.map(children, &do_render_outline/1))
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue