Refactor the zola regex out into a constant.

This commit is contained in:
Jessica Canady 2024-05-23 16:47:48 -04:00
parent 98d0555b17
commit 523b36d823
Signed by: phoenix
SSH key fingerprint: SHA256:aaLOzOrLi+0n4eDZNQKH97PehwRt6KSE5fYJc+ZRKCQ

View file

@ -1,5 +1,6 @@
defmodule JOL.Blog.Parser do
# Parses blog posts.
@zola_post_regex ~r/\+\+\+\n(?<attrs>.*)\n\+\+\+\n\n(?<body>.*)/s
@doc """
Psrses a Zola-style blogpost.
"""
@ -12,7 +13,7 @@ defmodule JOL.Blog.Parser do
}, String.t()}
def parse(_path, content) do
%{"attrs" => attrs, "body" => body} =
Regex.named_captures(~r/\+\+\+\n(?<attrs>.*)\n\+\+\+\n\n(?<body>.*)/s, content)
Regex.named_captures(@zola_post_regex, content)
{:ok, toml_attrs} = Toml.decode(attrs)