静态网站生成

发布于 2024-11-30 11:06:56 字数 903 浏览 1 评论 0原文

我需要一种简单的方法来生成静态网页,以便我可以使用 Apache 或 Nginx 提供它们。目前我正在使用 SproutCore 的构建工具(Abbot)来生成静态页面,但这有点麻烦,因为它是为构建 SproutCore 应用程序而不是非 SproutCore HTML 页面而设计的。

以下是我的要求:

  • 必须组合 Javascript,并且
  • 必须组合缩小的 CSS 文件
  • 每个图像/CSS/Javascript 资产必须具有唯一的 URL,以便更好地缓存(查询字符串不够)
  • 资产 URL 仅在真正更改时才应不同
  • 本地化支持彻底的 HTML、CSS、Javascript 和图像文件
  • 漂亮的模板引擎,带有布局、部分等。

以下是我找到的可能的解决方案:

对此有什么想法吗?

经过漫长的评估过程后,我决定使用 Middleman。它确实有效,我喜欢它的简单性,而且我可以使用现有的 Rack 组件。

最好的问候,

佩卡·马蒂拉

I need an easy way to generate static web pages so that I can serve them up with Apache or Nginx. Currently I am using SproutCore's build tool (Abbot) to generate static pages but that is a little bit cumbersome as it is designed for building SproutCore apps, not non-SproutCore HTML pages.

Here are my requirements:

  • Javascript must be combined and minified
  • CSS files must be combined
  • Each image / CSS / Javascript asset must have unique URL for better caching (query string isn't enough)
  • Asset URL should be different only when it really changes
  • Localization support thorough HTML, CSS, Javascript and image files
  • Nice template engine with layouts, partials etc.

Here are possible solutions I have found:

Any thoughts on this?

After a longish evaluation process I have decided to use Middleman. It does the trick and I love its simplicity and the fact that I can use existing Rack components with it.

Best Regards,

Pekka Mattila

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

小巷里的女流氓 2024-12-07 11:06:56

我是 Middleman 的创建者,很乐意帮助您轻松使用 Middleman。我的主要目标是为用户提供 Rails 的强大功能,但专注于静态开发。 Middleman 的一些实际代码是 Ab 的简化版本

I'm the creator of Middleman and would be eager to help you get comfortable using Middleman. My main goal is to give users the power of Rails, but focused on static development. Some of the actual code of Middleman is simplified versions of Ab

童话里做英雄 2024-12-07 11:06:56

这就是我所做的:

  • Ruby on Rails 3 与 高电压 Gem,这使得它简单的
    使用通用模板提供静态页面主体。它需要一个
    路由中的简单条目(您可以使用命名空间来创建
    等级制度)。

  • Apache 反向代理到独立的 Passenger(使用 nginx I
    相信)来运行 Rails 应用程序。 本文介绍了如何
    配置它。

独立乘客将读取 URL,查看 /public 中是否有相应的带有 .html 的文件,并提供该文件。如果没有找到,它将调用 Rails 并生成页面。本质上,页面缓存,可以选择发布带或不带 .html 的 URL。 Passenger 文档中有一个专门关于页面缓存的部分。

至于组合和缩小 js 和 css,这里有一个很好的 stackoverflow 线程

Rails 具有出色的 i18n/l10n 支持。

Rails 模板引擎非常好用。如果您愿意,也可以使用 HAML。

对于你的第三点和第四点,我有点困惑。您希望将 css 和 js 结合起来,但又希望每个都有自己的 URL。在 Rails 中,资产标签上的“cache => true”指令负责添加一个查询字符串参数,该参数会随着内容的变化而变化,这是一个相当传统的方案。我不确定你在什么环境下工作,这是行不通的。我使用过的任何 CDN 都可以正常工作,正确实现 HTTP 规范的 Web 服务器也是如此。无论如何,更改 URL 中的实际路径或文件将需要更改对其的所有引用。或许我理解有误?

Here's what I do:

  • Ruby on Rails 3 with the High Voltage Gem, which makes it easy
    to serve a static page body using the common templates. It requires a
    simple entry in the routes (and you can use namespaces to create a
    hierarchy).

  • Apache reverse proxy to stand-alone Passenger (which uses nginx I
    believe) to run the Rails app. This article describes how to
    configure it.

Stand-alone passenger will read the URL, see if there is a corresponding file in /public with the .html on it, and serve that. If not found, it will invoke Rails and generate the page. In essence, page caching, with the option of publishing your URLs with or without the .html. There is a section in the Passenger docs about page caching specifically.

As far as combining and minifying js and css, here's a good stackoverflow thread.

Rails has excellent i18n/l10n support.

Rails template engine is very nice to work with. And you can use HAML if you prefer.

For your 3rd and 4th points, I'm a little confused. You want css and js combined, but then you want each to have it's own URL. In Rails, the "cache => true" directive on asset tags takes care of adding a query string parameter that changes when the content does, which is a fairly traditional scheme. I'm not sure what context you are working in where that would not work. Any CDN I've ever used works fine with that, as does an web server implementing the HTTP spec correctly. Anyway, changing the actual path or file in the URL would require changing all references to it. Maybe I'm misunderstanding?

欲拥i 2024-12-07 11:06:56

我认为 Monkeyman 拥有您需要的模板引擎。可以将其视为 Middleman 的 Scala 小兄弟。目前还没有那么成熟或功能丰富,但我们最终会到达那里。当前版本支持 HAML、Jade、SSP 布局、Markdown 内容以及其他一些功能。

Monkeyman has the template engine you need, I think. Think of it as Middleman's little Scala brother. Nowhere as mature or feature rich yet, but we'll get there eventually. The current incarnation supports HAML, Jade, SSP for layouts, Markdown for content and a couple of other things.

茶底世界 2024-12-07 11:06:56

没有任何特殊订单

Without any special order

韶华倾负 2024-12-07 11:06:56

您或许还应该查看 mod_pagespeed。它至少会给你这个:

  • Javascript 必须被组合并且缩小的
  • CSS 文件必须被组合
  • 每个图像/CSS/Javascript 资源必须有唯一的 URL,以便更好的缓存(查询字符串是不够的)
  • 资源 URL 仅当它确实存在时才应该不同它

不会给你这个:

  • 本地化支持彻底的 HTML、CSS、Javascript 和图像文件
  • 漂亮的模板引擎,带有布局、部分等。

You should probably also checkout mod_pagespeed. It will at least give you this:

  • Javascript must be combined and minified
  • CSS files must be combined
  • Each image / CSS / Javascript asset must have unique URL for better caching (query string isn't enough)
  • Asset URL should be different only when it really changes

It won't give you this:

  • Localization support thorough HTML, CSS, Javascript and image files
  • Nice template engine with layouts, partials etc.
心作怪 2024-12-07 11:06:56

您可以查看docpad。它是用 coffeescript 编写的,并在 上运行Node.js。它是基于文档的,您在其中编写一些文档和布局,它将编译它们并将它们写入 out 目录中。您可以通过插件编写多种语言的文档

。它还支持多级文件编译。例如,从 ecomarkdownhtml

它的另一个很棒的功能是您可以查询文档中生成的其他文档。例如,在第一页中,您可以使用类似以下内容来获取所有博客文章:

database.findAll({url : /posts/})

这将返回 url 中包含帖子的所有文档。

You can have a look at docpad. It's written in coffeescript and runs on Nodejs. It is document based, where you write some documents and layouts, it will compile them and write them in the out directory. You can write documents in a lot of languages via plugins

It also supports multiple level of file compilation. For example from eco to markdown to html.

Another great feature of it is that you can query on other documents being generated in a document. For example in the first page, you have something like this to get all blog posts:

database.findAll({url : /posts/})

Which will return all documents having posts in their url.

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