I like Rails. And I increasingly really like Jekyll. The "why" of this particular mashup deserves a much more thorough writeup. For now, here's the "what."
(Up-front disclosure: I don't use this in production [anymore]; see the end of this readme for alternate takes on a similar theme.)
Look around. It's Rails.
But wait, there's more! According to this _config.yml, there's a Jekyll app hiding mostly in app/static! And it's generating the entirety of the Rails app's public directory!
There are some other opinions in the _config.yml file (Redcloth, Pygments), but it's all pretty minimal right now.
Because I rather like the Rails asset pipeline, and want to use all of its strengths from within Jekyll, I wrote a small Jekyll plugin to provide an asset_path tag. This tag uses the Rails environment's own Sprockets environment in Rails.application.assets to find assets and their digest paths.
Boom: Jekyll is using the Rails apps stylesheets, in all their compiled, minified, gzipped, digested glory.
Finally, I straight-up .gitignore the public directory. I then wire up a simple rake task to run a naive Jekyll build before the assets:precompile task presumably being called elsewhere in your production deploy scripts.
This app is a bit of exploration and experimentation. There is more exposition to come based on what I learn in here. Hopefully the result will describe a standard, de facto way for integrating Jekyll into a Rails app.
For now, feedback is welcome! In particular, I want to talk about:
/assets in my asset_path tag, and the (lack of) options in the jekyll:build task. Mostly late evening laziness on my part. Can these be made more flexible and robust?Hit me up on the Twitters: @nz_
If you're hosting on Heroku you won't be able to lean on the assets:precompile dependency for the jekyll
task so you should delete the jekyll.rake task file and, instead, precompile your assets locally and check
them into your repo. Otherwise the files would still be compiled on deploy, but would disappear as files not
checked into git are eventually deleted.
When running rake assets:precompile it will do so within your production environment. Remember that assets
are given a different digest per environment. If you compile jekyll files without RAILS_ENV=production the
asset_path plugin will instead be run in a development context. As a result the digests will not match. The lesson?
Run both with RAILS_ENV set as production.
rake assets:precompile # RAILS_ENV=production is optional here
RAILS_ENV=production jekyll build
git clone [email protected]:nz/jekyll-rails-hybrid.git
cd jekyll-rails-hybrid
bundle install
jekyll build
rails server
Enjoy!
Apparently this repo ranks well on Google for "jekyll rails" — if you have other links to similar ideas, I'll happily add them here, just send me a pull request.