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,11 +24,23 @@ defmodule LogsrvApi.Filesystem do
def all(Page) do
dir(:pages)
|> File.ls!
|> Enum.sort
|> Enum.map(fn(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)
|> Enum.sort(&sort/2)
end
def sort(a, b) do
Timex.compare(a.date, b.date) > 0
end
def all(Journal) do
dir(:journals)

View File

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