开发者

Static web site generation

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:

  • Create the site using Ruby on Rails, then get all resources using wget like http://usefulfor.com/ruby/2009/03/23/use-rails-to-create-a-static-site-rake-and-subversion/
  • Use Middleman: 开发者_如何学JAVAhttp://middlemanapp.com

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


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


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?


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.


Without any special order

  • jekyll - quite simple
  • middleman - a lot of funcionalities
  • nanoc - a lot of funcionalities
  • stasis - use controllers
  • staticmatic
  • frank
  • gumdrop
  • ruby on rails + wget
  • ruby on rails + high voltage + apache reverse proxy


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜