Class: Jekyll::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/strapi/site.rb

Overview

Add helper methods for dealing with Strapi to the Site class

Instance Method Summary collapse

Instance Method Details

#endpointObject



21
22
23
# File 'lib/jekyll/strapi/site.rb', line 21

def endpoint
  has_strapi? and @config['strapi']['endpoint'] or "http://localhost:1337/api"
end

#has_strapi?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/jekyll/strapi/site.rb', line 13

def has_strapi?
  @config['strapi'] != nil
end

#has_strapi_collections?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/jekyll/strapi/site.rb', line 17

def has_strapi_collections?
  has_strapi? and @config['strapi']['collections'] != nil
end

#parameterObject



25
26
27
# File 'lib/jekyll/strapi/site.rb', line 25

def parameter
  has_strapi? and @config['strapi']['parameter'] or "populate=*"
end

#strapiObject



4
5
6
# File 'lib/jekyll/strapi/site.rb', line 4

def strapi
  return nil unless has_strapi?
end

#strapi_collection(collection_name) ⇒ Object



47
48
49
# File 'lib/jekyll/strapi/site.rb', line 47

def strapi_collection(collection_name)
  strapi_collections[collection_name]
end

#strapi_collectionsObject



8
9
10
11
# File 'lib/jekyll/strapi/site.rb', line 8

def strapi_collections
  return Array.new unless has_strapi_collections?
  @strapi_collections ||= Hash[@config['strapi']['collections'].map {|name, config| [name, Strapi::StrapiCollection.new(self, name, config)]}]
end


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jekyll/strapi/site.rb', line 29

def strapi_link_resolver(collection = nil, document = nil)
  return "/" unless collection != nil and @config['strapi']['collections'][collection]['permalink'] != nil

  url = Jekyll::URL.new(
    :template => @config['strapi']['collections'][collection]['permalink'],
    :placeholders => {
      :id => document.id.to_s,
      :uid => document.uid,
      :slug => document.attributes.slug,
      :type => document.type,
      :date => document.attributes.date,
      :title => document.attributes.title
    }
  )

  url.to_s
end