Created
June 26, 2019 20:17
Parse frontmatter in Elixir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract(changeset) do | |
file_name = changeset.data.name | |
data = File.read!("#{@data_folder}/pages/#{file_name}") | |
case String.split(data, ~r/\n-{3,}\n/, parts: 2) do | |
[""] -> | |
%{frontmatter: nil, content: nil} | |
[frontmatter, content] -> | |
%{ | |
frontmatter: parse_yaml(frontmatter), | |
content: content | |
} | |
_ -> | |
%{frontmatter: nil, content: nil} | |
end | |
# {parse_yaml(frontmatter), Earmark.to_html(markdown)} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment