Worm with Glasses

Coding • DevOps • Personal

Mar 13, 2005

Added Blogroll

I spent some more time tweaking my Template Toolkit templates and scripts to allow me to generate the update entries in a consistent manner. I have one WRAPPER template fragment that generates the blog-entry HTML and then the index.html template for the site grabs the five most recent entries to display on the page.

I also added a new Emacs binding to help generate the timestamp for the entry. Two key-strokes later and I have the correct entry. The Emacs Lisp I use in my .emacs is:

(define-skeleton datetime-in-t-format
  "Return the current date/time in T-combined format"
  (format-time-string "%Y%m%dT%H%M%S"))
(global-set-key [?\C-c ?\C-w] 'datetime-in-t-format)

The entries are placed in the blog directory and then my index.html template processes the five more recent with the following Template Toolkit code:

# Grab the five most recent blog entries
USE dir = Directory('./src/blog', recurse=1);
SET count = 5;
FOREACH subdir = dir.dirs.reverse;
  FOREACH file = subdir.files.reverse;
    NEXT IF file.name.match('~$');
    SET blogpath = "blog/${subdir.name}/${file.name}";
    PROCESS $blogpath path = blogpath filename = file.name;
    count = count - 1;
    LAST IF count == 0;
  LAST IF count == 0;

It’s a nice easy system for me to update the entries on the site.