Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: http://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

like image 241
Pekka Mattila Avatar asked Aug 20 '11 11:08

Pekka Mattila


People also ask

What is a static site generation?

A static site generator is a tool that generates a full static HTML website based on raw data and a set of templates. Essentially, a static site generator automates the task of coding individual HTML pages and gets those pages ready to serve to users ahead of time.

How do I choose a static site generator?

The better you can identify the experience you'd like your visitors to have, the easier it will be to pick the feature set that can best support it. There are so many static site generators out there that you can find one in nearly every language and framework.

What is the easiest static site generator?

Jekyll (opens in new tab) is a simple and effective static site generator that's been around since 2008, and it remains one of the most popular free options on the market. It uses a repetitive and straightforward command structure that makes it easy to use, even for command line beginners.


3 Answers

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

like image 154
Thomas Reynolds Avatar answered Sep 18 '22 08:09

Thomas Reynolds


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?

like image 20
pduey Avatar answered Sep 21 '22 08:09

pduey


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.

like image 41
Wilfred Springer Avatar answered Sep 20 '22 08:09

Wilfred Springer