Begin to implement reading a page

This commit is contained in:
Ryan Pandya 2022-09-05 02:09:17 -07:00
parent 9c2d5861c5
commit ad86f60b58
5 changed files with 45 additions and 3 deletions

View File

@ -16,10 +16,27 @@ defmodule LogsrvApi do
def journals do def journals do
@repo.all(Journal) @repo.all(Journal)
end end
def journal(date) do def journal(str) do
{:ok, date} = Filesystem.to_date(str)
@repo.get!(Journal, date) @repo.get!(Journal, date)
end end
# Todo - def get_by def get_by_id(id) do
# Try to guess whether it's a page or a journal
{_, date} = Filesystem.to_date(id)
case date do
:invalid_format ->
IO.puts(id)
page(id)
_ ->
IO.puts(id)
journal(date)
end
end
def read(page) do
@repo.read(page)
end
end end

View File

@ -6,9 +6,11 @@ defmodule LogsrvApi.Journal do
tags = [:fun] tags = [:fun]
%{ %{
type: Journal,
date: date, date: date,
filename: fd, filename: fd,
tags: tags tags: tags
} }
end end
end end

View File

@ -6,4 +6,12 @@ defmodule LogsrvWeb.PostController do
journals = LogsrvApi.journals() journals = LogsrvApi.journals()
render(conn, "index.html", pages: pages, journals: journals) render(conn, "index.html", pages: pages, journals: journals)
end end
def show(conn, %{"id" => id}) do
pages = LogsrvApi.pages()
journals = LogsrvApi.journals()
post = LogsrvApi.get_by_id(id)
content = post |> LogsrvApi.read
render(conn, "post.html", post: post, pages: pages, journals: journals, content: content)
end
end end

View File

@ -11,7 +11,11 @@
<h2>Journals</h2> <h2>Journals</h2>
<ul> <ul>
<%= for journal <- @journals do %> <%= for journal <- @journals do %>
<li><strong><%= journal.date %></strong> (<%= journal.filename %>)</li> <li>
<a href={post_path journal}>
<strong><%= journal.date %></strong> (<%= journal.filename %>)
</a>
</li>
<% end %> <% end %>
</ul> </ul>
</article> </article>

View File

@ -1,3 +1,14 @@
defmodule LogsrvWeb.PostView do defmodule LogsrvWeb.PostView do
use LogsrvWeb, :view use LogsrvWeb, :view
import LogsrvApi.Journal
def post_path(post) do
"/post/#{post.filename}"
end
def content(post) do
IO.puts(post.filename)
post.filename |> Journal.locate |> LogsrvApi.read
end
end end