Class: Jekyll::ContentfulEntryPage

Inherits:
Page
  • Object
show all
Defined in:
lib/jekyll-contentful.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, entry, content_type_name, prefix) ⇒ ContentfulEntryPage

Returns a new instance of ContentfulEntryPage.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jekyll-contentful.rb', line 9

def initialize(site, entry, content_type_name, prefix)
  
  @site = site
  @base = site.source
  @name = 'index.html'
  
  content_type_slug = Utils.slugify content_type_name

  layout_filename = site.layouts.key?(content_type_slug) ? "#{content_type_slug}.html" : "default.html"
  self.read_yaml(File.join(@base, '_layouts'), layout_filename)

  # stringify hash keys
  fields = Jekyll::Utils.stringify_hash_keys(entry.fields)
  self.data['contentful_fields'] = fields

  display_field = entry.content_type.resolve.display_field
  self.data['title'] = fields[display_field] if display_field

  self.data["contentful_id"] = entry.id
  self.data["contentful_locale"] = entry.locale

  # If there is a title fields make it the url
  page_title_slug = Utils.slugify(self.data["title"] || "")
  @dir = "/#{prefix}#{content_type_slug}/#{page_title_slug}"
  
  self.process(@name)
end