Mercurial > blahgd
changeset 21:1f5cf4308249
sidebar: display archive entries
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Wed, 04 Feb 2009 15:39:15 -0500 |
parents | b1965983e1c0 |
children | 71493f7ab51d |
files | html.c sar.c sar.h |
diffstat | 3 files changed, 52 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/html.c Wed Feb 04 15:22:33 2009 -0500 +++ b/html.c Wed Feb 04 15:39:15 2009 -0500 @@ -133,11 +133,36 @@ closedir(dir); } +static void __invoke_for_each_archive(struct post *post, void(*f)(struct post*, char*)) +{ + struct dirent *de; + DIR *dir; + + dir = opendir("data/by-month"); + if (!dir) + return; + + while((de = readdir(dir))) { + if (!strcmp(de->d_name, ".") || + !strcmp(de->d_name, "..")) + continue; + + f(post, de->d_name); + } + + closedir(dir); +} + static void __sidebar_cat_item(struct post *post, char *catname) { cat(post, catname, "templates/sidebar-cat-item.html", repltab_cat_html); } +static void __sidebar_arch_item(struct post *post, char *archname) +{ + cat(post, archname, "templates/sidebar-archive-item.html", repltab_arch_html); +} + void html_sidebar(struct post *post) { cat(post, NULL, "templates/sidebar-top.html", repltab_html); @@ -145,10 +170,9 @@ __invoke_for_each_cat(post, ".", __sidebar_cat_item); cat(post, NULL, "templates/sidebar-middle.html", repltab_html); -#if 0 - for_each_month() - cat(post, NULL, "templates/sidebar-archive-item.html", repltab_html); -#endif + + __invoke_for_each_archive(post, __sidebar_arch_item); + cat(post, NULL, "templates/sidebar-bottom.html", repltab_html); }
--- a/sar.c Wed Feb 04 15:22:33 2009 -0500 +++ b/sar.c Wed Feb 04 15:39:15 2009 -0500 @@ -1,4 +1,5 @@ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/types.h> #include <dirent.h> @@ -126,9 +127,31 @@ {"", NULL}, }; +static void echo_arch_name(struct post *post, void *data) +{ + char *name = data; + + fprintf(post->out, "%s", name); +} + +static void echo_arch_desc(struct post *post, void *data) +{ + char *name = data; + + fprintf(post->out, "%s %c%c%c%c", up_month_strs[atoi(name+4)-1], + name[0], name[1], name[2], name[3]); +} + +static struct repltab_entry __repltab_arch_html[] = { + {"ARCHNAME", echo_arch_name}, + {"ARCHDESC", echo_arch_desc}, + {"", NULL}, +}; + struct repltab_entry *repltab_html = __repltab_html; struct repltab_entry *repltab_comm_html = __repltab_comm_html; struct repltab_entry *repltab_cat_html = __repltab_cat_html; +struct repltab_entry *repltab_arch_html = __repltab_arch_html; static int invoke_repl(struct post *post, void *data, char *cmd, struct repltab_entry *repltab)
--- a/sar.h Wed Feb 04 15:22:33 2009 -0500 +++ b/sar.h Wed Feb 04 15:39:15 2009 -0500 @@ -14,6 +14,7 @@ extern struct repltab_entry *repltab_html; extern struct repltab_entry *repltab_comm_html; extern struct repltab_entry *repltab_cat_html; +extern struct repltab_entry *repltab_arch_html; #define COPYCHAR(ob, oi, c) do { \ ob[oi] = c; \