Compare commits

...

2 Commits

Author SHA1 Message Date
Ryan Pandya
f6f71d1ee5 Broken! 2022-09-07 15:45:38 -07:00
Ryan Pandya
33064a43da Warning: Currently broken! 2022-09-07 15:45:30 -07:00
3 changed files with 27 additions and 7 deletions

View File

@ -0,0 +1,7 @@
defmodule LogsrvApi.Crawler do
alias LogsrvApi.{Filesystem,Page,Journal}
def crawl do
Filesystem.
end
end

View File

@ -24,11 +24,23 @@ 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) ->
case fd |> File.ls do
{:error, _} ->
IO.puts("Error on #{fd}")
Page.init(fd) Page.init(fd)
pages ->
IO.puts(pages)
pages |> Enum.map(fn(page) ->
"pages/#{page}" |> Page.init
end) end)
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 def all(Journal) do
dir(:journals) dir(:journals)

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