module Syntropy
def self.parse_markdown_file(path, opts)
-
(Array)
- an tuple containing properties, contents
Parameters:
-
path
(String
) -- file path
def self.parse_markdown_file(path, opts) content = IO.read(path) || '' atts = {} # Parse date from file name m = path.match(DATE_REGEXP) atts[:date] ||= Date.parse(m[1]) if m if (m = content.match(FRONT_MATTER_REGEXP)) front_matter = m[1] content = m.post_match yaml = YAML.safe_load(front_matter, **YAML_OPTS) atts = atts.merge(yaml) end if opts[:location] atts[:url] = path .gsub(/#{opts[:location]}/, '') .gsub(/\.md$/, '') end [atts, content] end