Class: Benoit::PageMetadata::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/benoit/page_metadata/parser.rb

Constant Summary collapse

KEY_CONVERTERS =
{
  "date" => ->(value){
    Kronic.parse(value)
  }
}

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/benoit/page_metadata/parser.rb', line 20

def self.parse(input)
  content = input.read
  if FrontMatter.has_frontmatter?(content)
    response = FrontMatter.parse(content)
    response.merge(response) do |key,original_value|
      if KEY_CONVERTERS.key?(key)
        KEY_CONVERTERS[key].(original_value)
      else
        original_value
      end
    end
  else
    {}
  end
end

.should_parse?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/benoit/page_metadata/parser.rb', line 15

def self.should_parse?(path)
  FrontMatter.file_might_have_frontmatter?(path) ||
    FrontMatter.file_has_frontmatter?(path)
end