This commit is contained in:
Ryan Pandya 2022-09-07 15:45:38 -07:00
parent 33064a43da
commit f6f71d1ee5
2 changed files with 20 additions and 7 deletions

View File

@ -24,10 +24,22 @@ defmodule LogsrvApi.Filesystem do
def all(Page) do def all(Page) do
dir(:pages) dir(:pages)
|> File.ls! |> File.ls!
|> Enum.sort
|> Enum.map(fn(fd) -> |> Enum.map(fn(fd) ->
Page.init(fd) case fd |> File.ls do
{:error, _} ->
IO.puts("Error on #{fd}")
Page.init(fd)
pages ->
IO.puts(pages)
pages |> Enum.map(fn(page) ->
"pages/#{page}" |> Page.init
end)
end
end) end)
|> Enum.sort(&sort/2)
end
def sort(a, b) do
Timex.compare(a.date, b.date) > 0
end end
def all(Journal) do def all(Journal) do

View File

@ -49,13 +49,14 @@ defmodule LogsrvApi.Page do
{:nil, Earmark.as_html!(data)} {:nil, Earmark.as_html!(data)}
end end
end end
defp parse_yaml(yaml) do def parse_yaml(yaml) do
[parsed] = :yamerl_constr.string(yaml) yaml
parsed |> :yamerl_constr.string
|> List.flatten
end end
defp extract({props, content}, post) do defp extract({props, content}, post) do
%{post | %{post |
title: get_prop(props, "title") || post.title, title: get_prop(props, "title") |> to_string || post.title,
tags: get_prop(props, "tags"), tags: get_prop(props, "tags"),
content: content} content: content}
end end
@ -65,7 +66,7 @@ defmodule LogsrvApi.Page do
else else
case :proplists.get_value(String.to_char_list(key), props) do case :proplists.get_value(String.to_char_list(key), props) do
:undefined -> nil :undefined -> nil
x -> to_string(x) x -> x
end end
end end
end end