Running on Nesta

Blog Projects
ruby

My Mephisto installation finally went fubar. I had to search for new blog engine. It needed to be simple, easy to customize, support Textile and preferably be built on Sinatra. I ended up choosing Nesta. It did not have Textile support so I wrote a patch. This proved Nesta is really easy to customize. Nesta also provided ready made scripts for importing from Mephisto. This made converting from one system to another a breeze.

The Setup

Nesta does not use databases. Instead blog entries are written as text files. I use TextMate for writing the entries which are formatted using Textile. Entries are stored and deployed using git via Github.

Pages are served using funky cached setup. When page is requested rewrite rules check if static version of the page is available. If not the request goes to Nesta. Nesta generates the page and writes a static version of page to cache folder on disc. Apache then serves future requests directly from cache.

Here are the currently used rewrite rules:

# Sample .htaccess file for Nesta funky caching
# Rewrite index to check for static.
RewriteCond  %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^$ /cache/index.html [L,QSA]

# Rewrite to check for cached page from cached folder.
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /cache/$1.html [L,QSA]

# Everything else goes to Nesta
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-l
RewriteRule (.*) http://127.0.0.1:4567%{REQUEST_URI} [L,P,QSA]

Code Highlighting

Code highlighting is done by with rack-codehighlighter. This actually caused a problem. Nesta has an inbuilt caching system which works great. However code since highlighting is done in Rack middleware Nesta created the cache file before request reached highlighter. Thus when Apache served the cached file code was not highlighted anymore.

I worked around this by disabling Nesta caching and writing funky cache middleware for Rack. This should be the last middleware to call. I am sure someone has done it before. It was a good learning experience with Rack.



When asking a question please include an URL to example page where the problem occurs. If you have longer code examples please use pastie.org.
CATEGORIES
Built using the awesome Flat UI Pro framework by Designmodo.

© 2013 Mika Tuupola.