Closed cjavilla-stripe closed 2 years ago
Solved!
I had to new up a Loader and pass it into parse_file like this:
class PostsController < ApplicationController
def index
files = Dir.glob(File.join(Rails.root, "posts", "*.md"))
@posts = files.map do |f|
parsed = FrontMatterParser::Parser.parse_file(
f,
loader: FrontMatterParser::Loader::Yaml.new(allowlist_classes: [Date])
)
Post.new(f, parsed.front_matter)
end
end
That's it :slightly_smiling_face:
@waiting-for-dev Would it make sense to update this gem to include Date
as allowed by default?
It is very common to have a date in the front matter. It would be nice if it was accepted without raising exceptions.
Thanks for your feedback, @collimarco. I think it makes sense to have it as a default.
When I try to parse a doc that looks like this:
It fails with:
Full trace:
This is my PostsController:
My goal is to iterate over my blog posts, authored in markdown with front matter that contains title and date and render a simple list. My bet is we need to pass some permitted classes to the yaml loader?
This conversation seems relevant: https://github.com/ruby/psych/issues/262