class JekyllPagesApiSearch::SearchPageLayouts
We have to essentially recreate the ::Jekyll::Layout constructor to loosen the default restriction that layouts be included in the site source.
Copied from guides_style_18f/layouts.rb. Could probably be extracted into another gem.
Constants
- DEFAULT_LAYOUT
- LAYOUTS_DIR
Public Class Methods
new(site, layout_name)
click to toggle source
# File lib/jekyll_pages_api_search/search_page_layouts.rb, line 16 def initialize(site, layout_name) @site = site @base = LAYOUTS_DIR @name = "#{layout_name}.html" @path = File.join(@base, @name) @relative_path = @path.sub(@base, '') parse_content_and_data(File.join(@base, name)) process(name) end
register(site)
click to toggle source
# File lib/jekyll_pages_api_search/search_page_layouts.rb, line 39 def self.register(site) site.layouts[DEFAULT_LAYOUT] ||= new(site, DEFAULT_LAYOUT) end
Private Instance Methods
parse_content_and_data(file_path)
click to toggle source
# File lib/jekyll_pages_api_search/search_page_layouts.rb, line 26 def parse_content_and_data(file_path) @data = {} @content = File.read(file_path) front_matter_pattern = /^(---\n.*)---\n/m front_matter_match = front_matter_pattern.match(content) return unless front_matter_match @content = front_matter_match.post_match @data = SafeYAML.load(front_matter_match[1], safe: true) || {} end