jekyll-strapi
jekyll-strapi copied to clipboard
Error building Jekyll when using MySQL with Strapi
Terminal output: Jekyll Feed: Generating feed for posts Liquid Exception: Can't convert Integer into String. in /_layouts/posts.html bundler: failed to load command: jekyll (/Users/bogdan/.rbenv/versions/2.5.1/bin/jekyll) TypeError: Can't convert Integer into String. /Users/bogdan/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/addressable-2.6.0/lib/addressable/uri.rb:581:in `rescue in encode'
After an investigation, I found out that generic IDs from MySQL (used with Strapi) generates this error because of strapi_link_resolver() in site.rb receive parameter document as an object containing numeric id by default.
This is caused because the default Strapi database is MongoDB with IDs in default uuid format (string), right? And there is no fall back for the MySQL autoincrement numeric ID sent to addressable/uri.rb:581 causing to drop error when assigning uri.to_str (Jekyll::URL() method to_s use addressable/uri.rb which cant parse numeric values as uri )
There should be settings in Jekyll Strapi config for MySQL (or any rest api with numeric IDs).
Workarounds:
- If I change order for the :plceholders in a way that slug is before :id all works fine def strapi_link_resolver(collection = nil, document = nil)
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 => {
` :uid => document.uid,`
:slug => document.slug,
:id => document.id,
:type => document.type
}
)
url.to_s
end
- If @config has defined document_key and passed as document_key: slug for example
- enabled in Strapi model routes.json "path": "/
/:slug",
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 => @config['strapi']['collections'][collection]['document_key] ||= document.id,_
:uid => document.uid,
:slug => document.slug,
:type => document.type
}
)
url.to_s
end
Thank you for this report! Can you open a PR please. Will appreciate your contribution on this issue.
I'd just like to let you know that I installed the gem using the instructions on the README, but the latest version of the gem that was installed did not reflect the above change. I had to edit site.rb
with the .to_s
method to avoid to string/integer issue described above. Thanks for reporting this -- it solved my issue.
commenting # id => document.id helped me url = Jekyll::URL.new( :template => @config['strapi']['collections'][collection]['permalink'], :placeholders => { # :id => document.id, :uid => document.uid, :slug => document.slug, :type => document.type } )
The issue was fixed here https://github.com/strapi/jekyll-strapi/commit/c4d302b8cf569e08e3f536f114a00ad0bded312f but an official patch seems never released.