Rails 应用程序和 Jekyll 博客可以共存吗?

发布于 2024-10-10 04:34:10 字数 214 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

埋情葬爱 2024-10-17 04:34:10

...只需要弄清楚是否可以使用 http://my.app.com/blog
作为 url(知道 Jekyll 将使用自己的 url 运行自己的服务器进程)。

虽然 jekyll 的网络服务器可以工作,但使用 Rails 应用程序的网络服务器为所有页面提供服务可能会更容易、更简单、更安全。

做你想做的事情的最简单方法是 hooking jekyll 调用到你的服务器的 git 存储库,所以 jekyll 的每次推送时,静态内容都会自动添加到 Rails 应用的 public/blog/ 目录中。

  1. 在应用的 public 文件夹中创建一个名为 public/blog 的符号链接。使其指向 jekyll 存储库生成的 _site 文件夹。
  2. 在控制 jekyll 博客内容的 git 存储库上,添加一个 post-receive hook 执行以下操作:

    <前><代码>#!/bin/sh

    rm -rf_site

    杰基尔

这些是基本步骤。您可能必须正确配置读取权限,如果您使用的是 SCM(就像您应该的那样),请忽略 /blog/ 链接,如果您使用 Capistrano 或 Vlad 进行部署,则必须自动创建链接。

还有其他替代方案,例如使用真实的文件夹而不是符号链接,并让 jekyll 直接在那里生成内容,但我觉得我提供的方案是最干净的。

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

百善笑为先 2024-10-17 04:34:10

您会使用 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.

两相知 2024-10-17 04:34:10

几周前我也遇到了同样的问题。如果你真的必须使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文