changeset 33:ab4cc2b2e7ff

archive: mostly working
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 05 Feb 2009 21:26:55 -0500
parents bd3715c51969
children a1cf9bd7860f
files .gitignore Makefile archive.c html.c html.h
diffstat 5 files changed, 75 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.gitignore	Thu Feb 05 16:53:55 2009 -0500
+++ b/.gitignore	Thu Feb 05 21:26:55 2009 -0500
@@ -1,4 +1,5 @@
 index
 story
+archive
 
 tags
--- a/Makefile	Thu Feb 05 16:53:55 2009 -0500
+++ b/Makefile	Thu Feb 05 21:26:55 2009 -0500
@@ -3,7 +3,7 @@
 
 FILES=sar.c post.c xattr.c html.c dir.c
 
-all: story index
+all: story index archive
 
 clean:
 	rm -f story index
@@ -13,3 +13,6 @@
 
 story: story.c $(FILES)
 	$(CC) $(CFLAGS) -o $@ story.c $(FILES)
+
+archive: archive.c $(FILES)
+	$(CC) $(CFLAGS) -o $@ archive.c $(FILES)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/archive.c	Thu Feb 05 21:26:55 2009 -0500
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "post.h"
+#include "sar.h"
+#include "html.h"
+
+int main(int argc, char **argv)
+{
+	struct timespec s,e;
+	char *path_info;
+	int archid;
+	struct post post;
+
+	clock_gettime(CLOCK_REALTIME, &s);
+
+	post.out = stdout;
+
+	fprintf(post.out, "Content-Type: text/html\n\n");
+
+	path_info = getenv("PATH_INFO");
+
+	if (!path_info) {
+		fprintf(post.out, "Invalid archival #\n");
+		return 0;
+	}
+
+	archid = atoi(path_info+1);
+
+	memset(&post, 0, sizeof(struct post));
+	post.out = stdout;
+	post.title = "archive XYZ";
+
+	html_header(&post);
+	html_archive(&post, archid);
+	html_sidebar(&post);
+	html_footer(&post);
+
+	destroy_post(&post);
+
+	clock_gettime(CLOCK_REALTIME, &e);
+
+	fprintf(post.out, "<!-- time to render: %ld.%09ld seconds -->\n", (int)e.tv_sec-s.tv_sec,
+		e.tv_nsec-s.tv_nsec+((e.tv_sec-s.tv_sec) ? 1000000000 : 0));
+
+	return 0;
+}
--- a/html.c	Thu Feb 05 16:53:55 2009 -0500
+++ b/html.c	Thu Feb 05 21:26:55 2009 -0500
@@ -113,6 +113,26 @@
 }
 
 /************************************************************************/
+/*                           ARCHIVE INDEX                              */
+/************************************************************************/
+void html_archive(struct post *post, int archid)
+{
+	char path[FILENAME_MAX];
+	DIR *dir;
+
+	snprintf(path, FILENAME_MAX, "data/by-month/%d", archid);
+
+	dir = opendir(path);
+	if (!dir)
+		return;
+
+	sorted_readdir_loop(dir, post, __each_index_helper, NULL, SORT_DESC,
+			    HTML_INDEX_STORIES);
+
+	closedir(dir);
+}
+
+/************************************************************************/
 /*                           POST COMMENTS                              */
 /************************************************************************/
 static void __html_comment(struct post *post, struct comment *comm)
--- a/html.h	Thu Feb 05 16:53:55 2009 -0500
+++ b/html.h	Thu Feb 05 21:26:55 2009 -0500
@@ -5,6 +5,7 @@
 
 extern void html_story(struct post *post);
 extern void html_index(struct post *post);
+extern void html_archive(struct post *post);
 extern void html_comments(struct post *post);
 extern void html_sidebar(struct post *post);
 extern void html_header(struct post *post);