Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for api v4 collection #19

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 23 additions & 8 deletions lib/jekyll/strapi/collection.rb
Expand Up @@ -17,9 +17,12 @@ def generate?
@config['output'] || false
end

def path
"/#{@config['type'] || @collection_name}?_limit=10000"
end

def each
# Initialize the HTTP query
path = "/#{@config['type'] || @collection_name}?_limit=10000"
uri = URI("#{@site.endpoint}#{path}")
Jekyll.logger.info "Jekyll Strapi:", "Fetching entries from #{uri}"
# Get entries
Expand All @@ -34,14 +37,26 @@ def each
end

# Add necessary properties
result.each do |document|
document.type = collection_name
document.collection = collection_name
document.id ||= document._id
document.url = @site.strapi_link_resolver(collection_name, document)
end
case @config["api_version"]
when "v4"
result.data.each do |document|
document.type = collection_name
document.collection = collection_name
document.id ||= document._id
document.url = @site.strapi_link_resolver(collection_name, document)
end

result.each {|x| yield(x)}
result.data.each {|x| yield(x)}
else
result.each do |document|
document.type = collection_name
document.collection = collection_name
document.id ||= document._id
document.url = @site.strapi_link_resolver(collection_name, document)
end

result.each {|x| yield(x)}
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/strapi/site.rb
Expand Up @@ -7,7 +7,7 @@ def strapi

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)]}]
@strapi_collections ||= Hash[@config['strapi']['collections'].map {|name, config| [name, Strapi::StrapiCollection.new(self, name, config.merge("api_version" => @config['strapi']['api_version']))]} ]
end

def has_strapi?
Expand Down