module Middleman module CoreExtensions class FrontMatter def parse_yaml_front_matter(content, full_path) yaml_regex = /\A(?:(```|~~~)\s?)? (---\s*\n.*?\n?)^((?:\1|---)\s*$\n?)/mx if content =~ yaml_regex content = content.sub(yaml_regex, '') begin data = YAML.load($2) || {} data = data.symbolize_keys rescue *YAML_ERRORS => e app.logger. error "YAML Exception parsing #{full_path}: #{e.message}" return false end else return false end [data, content] rescue [{}, content] end end end end