diff --git a/lib/jol/blog/parser.ex b/lib/jol/blog/parser.ex index 7966931..9cd5cd0 100644 --- a/lib/jol/blog/parser.ex +++ b/lib/jol/blog/parser.ex @@ -4,6 +4,16 @@ defmodule JOL.Blog.Parser do %{"attrs" => attrs, "body" => body} = Regex.named_captures(~r/\+\+\+\n(?.*)\n\+\+\+\n\n(?.*)/s, content) - {attrs, String.trim(body)} + {:ok, toml_attrs} = Toml.decode(attrs) + + parsed_attrs = %{ + title: toml_attrs["title"], + draft: toml_attrs["draft"], + tags: toml_attrs["taxonomies"]["tags"] + } + + parsed_body = String.trim(body) + + {parsed_attrs, parsed_body} end end diff --git a/test/lib/blog/parser_test.exs b/test/lib/blog/parser_test.exs index 59d5b94..c886f4e 100644 --- a/test/lib/blog/parser_test.exs +++ b/test/lib/blog/parser_test.exs @@ -23,4 +23,9 @@ defmodule JOL.Blog.ParserTest do {_attrs, body} = Parser.parse("/fake/filename", post.content) assert body == "Body!" end + + test "parses the attrs from zola-style posts", post do + {attrs, _body} = Parser.parse("filepath", post.content) + assert attrs == %{title: "test post", draft: false, tags: ["howto", "hardware"]} + end end