It's always nice when code I write works the first time.
mod_blog advancing yet some more. I was going to embed the HTML within the module, but when I wrote some sample code (to make the archives on the current site) it just got real messy real quick and I didn't even bother finishing it up.
Instead, I quickly wrote code to process template files. This side works pretty much like I think I'm going to end up doing it. I set up a subdirectory containing the templates, each file containing just a portion of a much larger page. In effect, each file is a chunk of HTML code that is processed. During the processing, anything between double hash signs is taken as the name of a callback function.
So for example, in the HTML code I have:
<html> <head> <title>##title## - The Boston Diaries - Captain Napalm<title> </head>
And the callbacks are currently defined in C as such:
static void archive_callback(FILE *fpout,void *data) { struct tm *ptm = data; char date[BUFSIZ]; strftime(date,BUFSIZ,"%B %Y",ptm); fprintf(fpout,"%s",date); } /***************************************************/ void do_archive( FILE *fpout, int year, int month, int stday, int endday) { static struct chunk_callback cb = { "title" , archive_callback }; struct tm thisday; /* code to set thisday properly snipped */ ChunkProcess(fpout,"archivehead",&cb,1,&thisday); ChunkProcess(fpout,"bostontitle",NULL,0,NULL); ChunkProcess(fpout,"bartitle",&cb,1,&thisday); /* code to generate links for each day */ ChunkProcess(fpout,"end",NULL,0,NULL); }
The call to ChunkProcess() takes an output file, the name of the chunk to display, a structure declaring the callbacks, the size of that array, and an extra pointer that is passed to the callback, in this case, to a struct tm * to the date we're processing.
The only thing I may change is the way callbacks are registered, but the mechanics certainly work.