Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Rails app and a Jekyll blog live together?

I have a Rails app and I want to add a blog feature; my idea is to use Jekyll which is a great blog tool, I just need to figure out if it's possible to use http://my.app.com/blog as a url (knowing that Jekyll will run its own server process with its own url).

Does anybody know of a way to accomplish this? It'd be great to be able to do so. Best regards!

like image 713
Panchew Avatar asked Jan 04 '11 16:01

Panchew


4 Answers

... just need to figure out if it's possible to use http://my.app.com/blog as a url (knowing that Jekyll will run its own server process with its own url).

While jekyll's web server works, it will be probably easier, simpler and safer to use your rails app's webserver for serving all pages.

The simplest way of doing what you want is hooking a jekyll invocation to your server's git repository, so jekyll's static content is added automatically to your rails app's public/blog/ directory every time there is a push.

  1. Create a symbolink link called public/blog inside your app's public folder. Make it point to the generated _site folder of your jekyll repository.
  2. On the git repository that controls the contents of the jekyll blog, add a post-receive hook that does the following:

    #!/bin/sh
    
    rm -rf _site
    
    jekyll
    

Those are the basic steps. You might have to configure the read permissions properly, ignore the /blog/ link if you are using an SCM (like you should) and automate the link creation if you are using Capistrano or Vlad for deploying.

There are other alternatives, like using a real folder instead of a symbolic link and having jekyll generate stuff directly there, but I feel the one I'm presenting is the cleanest.

like image 64
kikito Avatar answered Nov 12 '22 00:11

kikito


Would you be using nginx to reverse-proxy the Rails app? If so, you should be able to just carve out an exception so /blog is served directly by nginx instead of forwarded to Rails.

like image 31
Hank Gay Avatar answered Nov 12 '22 02:11

Hank Gay


Check out this gem: https://github.com/zbruhnke/bloggy

And this blog post about it: https://blog.engineyard.com/2012/introducing-bloggy-a-simple-way-to-add-a-jekyll-blog-to-any-rails-application

like image 4
ContentDJ Avatar answered Nov 12 '22 01:11

ContentDJ


I had the same problem a few weeks ago. If you really have to use Jekyll, I think the best solution is to use the already mentioned Bloggy gem.

However, I wasn't satisfied with this solution, because you still have to duplicate or synchronize a lot of things like templates, routes, stylesheets, and so on. So I decided to implement my own simple Jekyll-like blog functionality in Rails.

You can find my article describing the implementation here: Create a simple Jekyll-like blog in your Rails 4 app.

like image 3
tbuehl Avatar answered Nov 12 '22 01:11

tbuehl