1 Jan 2013 ralsina   » (Master)

Client-rendered, one-URL, dynamic, static site.

My vacations end tomorrow. So, the time to spend hacking fun, personal, free stuff is going to be limited because of the time spent coding fun, free stuff for money. So, I decided to finish with a bit of whimsy.

I implemented a completely client-rendered, one-URL, dynamic blog. Which is actually totally static.

In fact, that blog is this blog, just with a twist. If you go to this URL you will see what's basically this very site, with comments and everything as usual. But if you click on "Previous Post" ... well, it stays in the same page, even though it displays a different post :-)

The magic is the new, experimental, dynamic task_mustache plugin for my static site generator, Nikola. which does the following:

  1. Renders post data as JSON files instead of HTML
  2. Creates a HTML file that is really a mustache.js template
  3. Creates a HTML file with some bits of Javascript that loads the template and the newest post's data.
  4. If you access that mustache.html with a fragment, it uses that to fetch JSON data and rewrite itself.

And that's it. It actually loads fast, and regenerates very fast, since it does much less than the real site. There are a bunch of things that will dump you out of the "dynamic" site, like tag links, and whatever, but it works surprisingly well (and if you want to theme it, it's just one template).

This is the first of a new kind of thing for Nikola, the "extra plugins". Basically, stuff that is too weird, specific or useless for the general distro, will go there, and to use those plugins, you have to create a plugins/ folder in your site and add it there manually.

Enjoy!

Syndicated 2013-01-01 19:03:43 from Lateral Opinion

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!