修正 2010 Bug

昨天写的帖子居然显示成 1910 年 >< 那时候还清朝呢 。。。

Setup Bamboo with Nginx

Using Nginx as a frontend for web apps has several advantages:

  • static files are served by nginx
  • application could pick a random port
  • free gzip on response
  • speed

Steps to setup Nginx with Bamboo

Static files

http {

  ...

  server {
      listen       80;
      server_name  jinjing.funkymic.com;

      location ~ ^/(theme|plugin|images|dl|media)/ {
        root   /home/jinjing/scm/git/haskell/jinjing-blog/public;
      }

      ...
  }
}

All it does is to let Nginx serve several sub paths under the blog's public path, e.g. public/theme.

Enable gzip

http {
    ...

    gzip  on;
    gzip_http_version 1.0;
    gzip_vary on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_buffers 16 8k;
    gzip_disable “MSIE [1-6].(?!.*SV1)”;
    gzip_types 

      text/plain
      text/html
      text/xml
      text/javascript
      text/css
      application/json
      application/x-javascript 
      application/xml
      application/xml+rss
      ;


    ...

Reverse proxy to Bamboo app

server {
    ...

    location / {
        proxy_pass http://localhost:3000; 
    }
}

That's it.

I also use an in-house cache middleware to cache any response from the blog. Whenever I update a post, I remove the cache database. It's not ideal, but good enough for my stupid blog.

With this setup, there's no space leak, no file handles leaks and performance can be squeezed to above 350 requests/sec.

新主题

把手头能测的浏览器全测了:

  • firefox for mac 3.5.4
  • firefox for linux 3.5.4
  • safari 4.0.3
  • webkit nightly 4.0.3 (6531.9 r50423)
  • chrome for mac 4.0.228.0
  • chrome for linux 4.0.222
  • opera 10.01 for mac

就是没 IE,干脆不找了,肯定是乱的。

这个主题和原来的页面结构一样,不过内部是纯 HTML5 了,评论被阉割了,先这样。。

典型的没事找事。

Photo plugin

I just released the second bamboo plugin: Photo!

It's a port of the previous photo-album plugin, I changed the syntax to be XML compatible, and the plugin now works at the middleware level.

Crap, I should have started my K-on project. I was extremely annoyed when I found that the current bamboo does not have this photo plugin capability, so here it is, another sleepless night.

The photo plugin, as the highlighting plugin, also uses the HXT library. Despite the complexity of HXT, I think it's a fairly good library: The abstraction is beautiful and working with it is a pleasure, though there was a steep learning curve for using the arrow abstraction.

Example:

< plugin 
  type="photo"
  name="09-07-05 Project K on"
/>
Bamboo theme

I just separated bamboo into

  • core
  • themes

So the engine can have multiple front-end, bamboo is also more lightweight :)

/==============================\
| code                 :  1436 |
| comment              :   106 |
|------------------------------|
| ratio:                       |
|   comment/code       :  0.07 |
\==============================/

As a result, when bamboo is bootstrapped by bamboo-launcher, the launcher imports both bamboo and bamboo-theme-blueprint, and download the template db directory accordingly.

Some attention to software engineering makes bamboo -Wall -fno-warn-orphans clean.

A note on using theme, there are 3 parts from a theme:

  • a theme module to import, this happens in code, as theme is now a parameter to the bamboo middleware
  • a theme specific resource pointer, this is configured in site.txt:theme_name, you then put js and css config options inside db/config/theme/theme_name.txt, see db/config/theme/blueprint.txt for example. The reason to have a theme resource field in site.txt is to allow the theme to be configured without re-compililation, which might take some time. However, a theme is not required to use the resource field.
  • the actual theme resource, placed under db/public/theme/theme_name, e.g. db/public/theme/blueprint.

So a theme is about both the code, that generates html, and static resources, referred from html. There could be a better approach, but I think separating code and data should be a pleasant experience.

The same applies to developing a theme, you need to provide both the code and data.

Finally the theme interface:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module Bamboo.Type.ThemeInterface where

import Bamboo.Type.State (State)
import Hack (Response)

data Interface =
Index
| IndexFeed
| Post
| Static
| Tag
| TagFeed
| Search
deriving (Show, Eq)

type Theme = Interface -> State -> IO Response
Bamboo 2009.6.6

I uploaded the newest bamboo to hackage, it is now in a very good shape to extend and customized.

I'm planing to do the following:

  • seperate view completely, provide a theme interface
  • port the current view to blueprint theme
  • start to add back plugins through middleware
  • lilypond rendering !!!

The last thing was what motivated me to do the rewrite, yes fakebook!

Bamboo rewrite

I'm going to rewrite Bamboo, here is what I have in mind:

  • tiny core
  • plugin through hack-middleware
    • photo album
    • video
    • audio
    • tex
    • syntax highlighting
    • pandoc markup
  • pure view in state monad
  • theming through a separation of controller and view, connected by a universal State, i.e. the theme interface.