Sha256: 896c6cc450a8323e9a8ec175eca6c4fb2d2bac6eb7e63978dfb9e9aebb6c737d
Contents?: true
Size: 824 Bytes
Versions: 11
Compression:
Stored size: 824 Bytes
Contents
require 'yaml' # Extract YAML frontmatter from data and build metadata table. class Gollum::Filter::YAML < Gollum::Filter # Regexp thanks to jekyll YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m def extract(data) data.gsub!(YAML_FRONT_MATTER_REGEXP) do @markup.metadata ||= {} begin frontmatter = ::YAML.safe_load(sanitize(Regexp.last_match[1])) @markup.metadata.merge!(frontmatter) if frontmatter.respond_to?(:keys) && frontmatter.respond_to?(:values) rescue ::Psych::SyntaxError, ::Psych::DisallowedClass, ::Psych::BadAlias => error @markup.metadata['errors'] ||= [] @markup.metadata['errors'] << "Failed to load YAML frontmater: #{error.message}" end '' end data end def process(data) data end end
Version data entries
11 entries across 11 versions & 1 rubygems