Can a Rails app and a Jekyll blog live together?

后端 未结 4 770
悲&欢浪女
悲&欢浪女 2021-01-30 11:35

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/bl

相关标签:
4条回答
  • 2021-01-30 11:48

    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

    0 讨论(0)
  • 2021-01-30 11:49

    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.

    0 讨论(0)
  • 2021-01-30 11:58

    ... 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.

    0 讨论(0)
  • 2021-01-30 12:10

    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.

    0 讨论(0)
提交回复
热议问题