Rails 应用程序和 Jekyll 博客可以共存吗?
我有一个 Rails 应用程序,我想添加博客功能;我的想法是使用 Jekyll,这是一个很棒的博客工具,我只需要弄清楚是否可以使用 http://my.app。 com/blog 作为 url(知道 Jekyll 将使用自己的 url 运行自己的服务器进程)。
有谁知道有什么方法可以实现这一目标?能够这样做就太好了。此致!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然 jekyll 的网络服务器可以工作,但使用 Rails 应用程序的网络服务器为所有页面提供服务可能会更容易、更简单、更安全。
做你想做的事情的最简单方法是 hooking jekyll 调用到你的服务器的 git 存储库,所以 jekyll 的每次推送时,静态内容都会自动添加到 Rails 应用的
public/blog/
目录中。public
文件夹中创建一个名为public/blog
的符号链接。使其指向 jekyll 存储库生成的_site
文件夹。在控制 jekyll 博客内容的 git 存储库上,添加一个 post-receive hook 执行以下操作:
<前><代码>#!/bin/sh
rm -rf_site
杰基尔
这些是基本步骤。您可能必须正确配置读取权限,如果您使用的是 SCM(就像您应该的那样),请忽略 /blog/ 链接,如果您使用 Capistrano 或 Vlad 进行部署,则必须自动创建链接。
还有其他替代方案,例如使用真实的文件夹而不是符号链接,并让 jekyll 直接在那里生成内容,但我觉得我提供的方案是最干净的。
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.public/blog
inside your app'spublic
folder. Make it point to the generated_site
folder of your jekyll repository.On the git repository that controls the contents of the jekyll blog, add a post-receive hook that does the following:
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.
您会使用 nginx 来反向代理 Rails 应用程序吗?如果是这样,您应该能够创建一个异常,以便
/blog
直接由 nginx 提供服务,而不是转发到 Rails。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.看看这个宝石: https://github.com/zbruhnke/bloggy
以及关于它的这篇博客文章: https://blog.engineyard.com/2012/introducing-bloggy-a-simple-way-to-add-a-jekyll-blog-to-any-rails-application
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
几周前我也遇到了同样的问题。如果你真的必须使用 Jekyll,我认为最好的解决方案是使用已经提到的 Bloggy gem。
然而,我对这个解决方案并不满意,因为你仍然需要复制或同步很多东西,比如模板、路由、样式表等等。所以我决定在 Rails 中实现我自己的简单的类似 Jekyll 的博客功能。
您可以在这里找到我描述实现的文章:在 Rails 4 应用中创建一个简单的类似 Jekyll 的博客。
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.