FABE: Viewing blog entries

Now that we have our main window ready and our database tuned up, we need to show the articles when users click on their links. Here is how we are going to do that.

We need to create a file view.jss to handle such requests, passing the entry id, in our case as a urlified id, so we can grab the post from the database and show it using a template already defined in view.html

There are two ways of calling our article viewer, an ugly version:

http://localhost/fabe/view.jss?url=helloworld

And the prettified version:

http://localhost/fabe/view/helloworld

I like it pretty, so in order to do the latter, we need to tell Apache to hide .jss extensions, and to send the id prettified as part of the url path. So copy this code and save it as .htaccess in the fabe folder:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d

# hide .jss extension
RewriteRule ^([^\.]+)$ $1.jss [NC,L]

# prettify urls
RewriteRule ^view/([a-z0-9]+) view.jss?url=$1

Ready to show the blog entry? here is the code for view.jss:

/* view.jss?url=anypost */

var view,model,data={};
model        = require('./models.jss');
data.post    = model.getPost(request.get.url);
data.entries = model.getLastEntries(10);
view         = new Template().process('view',data);
response.write(view);

And the code for our template you can get it from here view.html

Now, everytime you click on an entry link you can see it in all its splendorous grandeur.

Next, creating new entries...