generate excerpt from <!-- more --> placeholder

This commit is contained in:
Inhji 2023-09-09 23:46:59 +02:00
parent ad0d130fc8
commit 106f86521c
4 changed files with 46 additions and 40 deletions

View file

@ -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;
} }
} }

View file

@ -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,

View file

@ -72,30 +72,24 @@
<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">
<%= for channel <- @channels do %>
<li>
<a href={~p"/channel/#{channel.slug}"}>
<%= channel.name %>
</a>
</li>
<% end %>
</ul>
<ul> <h3>Elsewhere</h3>
<%= for channel <- @channels do %> <ul class="menu">
<li> <%= for identity <- @public_identities do %>
<a href={~p"/channel/#{channel.slug}"}> <li><a href={identity.url}><%= identity.name %></a></li>
<%= channel.name %> <% end %>
</a> </ul>
</li>
<% end %>
</ul>
</div>
<div class="menu">
<strong>Elsewhere</strong>
<ul>
<%= for identity <- @public_identities do %>
<li><a href={identity.url}><%= identity.name %></a></li>
<% end %>
</ul>
</div>
</nav> </nav>
</aside> </aside>

View file

@ -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"> </span>
<%= pretty_date(note.published_at) %> </header>
</span>
</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>