Mercurial > blahgd
changeset 25:9be67550f0bf
index display 10 stories
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 05 Feb 2009 16:15:43 -0500 |
parents | 692da6202633 |
children | 18373c0707b8 |
files | config.h dir.c dir.h html.c html.h index.c post.c xattr.c |
diffstat | 8 files changed, 57 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.h Thu Feb 05 16:15:43 2009 -0500 @@ -0,0 +1,7 @@ +#ifndef __CONFIG_H +#define __CONFIG_H + +#define HTML_INDEX_STORIES 10 + +#endif +
--- a/dir.c Thu Feb 05 15:59:55 2009 -0500 +++ b/dir.c Thu Feb 05 16:15:43 2009 -0500 @@ -27,7 +27,7 @@ int sorted_readdir_loop(DIR *dir, struct post *post, void(*f)(struct post*, char*, void*), void *data, - int updown) + int updown, int limit) { struct dirent *de; char **list = NULL; @@ -58,9 +58,12 @@ else qsort(list, count, sizeof(char*), cmp_desc); - for(i=0; i<count; i++) { + for(i=0; (i<count) && limit; i++) { f(post, list[i], data); free(list[i]); + + if (limit != -1) + limit--; } return 0;
--- a/dir.h Thu Feb 05 15:59:55 2009 -0500 +++ b/dir.h Thu Feb 05 16:15:43 2009 -0500 @@ -8,6 +8,6 @@ extern int sorted_readdir_loop(DIR *dir, struct post *post, void(*f)(struct post*, char*, void*), - void *data, int updown); + void *data, int updown, int limit); #endif
--- a/html.c Thu Feb 05 15:59:55 2009 -0500 +++ b/html.c Thu Feb 05 16:15:43 2009 -0500 @@ -7,6 +7,7 @@ #include <sys/stat.h> #include <unistd.h> +#include "config.h" #include "sar.h" #include "html.h" #include "dir.h" @@ -75,6 +76,42 @@ } /************************************************************************/ +/* INDEX */ +/************************************************************************/ +static void __each_index_helper(struct post *post, char *name, void *data) +{ + int postid = atoi(name); + struct post p; + + memset(&p, 0, sizeof(struct post)); + p.out = post->out; + + if (load_post(postid, &p)) + return; + + cat(&p, NULL, "templates/story-top.html", repltab_story_html); + cat(&p, NULL, "templates/story-middle.html", repltab_story_html); + cat_post(&p); + cat(&p, NULL, "templates/story-bottom.html", NULL); + + destroy_post(&p); +} + +void html_index(struct post *post) +{ + DIR *dir; + + dir = opendir("data/posts"); + 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) @@ -137,7 +174,7 @@ if (!dir) return; - sorted_readdir_loop(dir, post, __each_cat_helper, plist, SORT_ASC); + sorted_readdir_loop(dir, post, __each_cat_helper, plist, SORT_ASC, -1); closedir(dir); } @@ -157,7 +194,7 @@ if (!dir) return; - sorted_readdir_loop(dir, post, __cb_wrap, f, SORT_DESC); + sorted_readdir_loop(dir, post, __cb_wrap, f, SORT_DESC, -1); closedir(dir); }
--- a/html.h Thu Feb 05 15:59:55 2009 -0500 +++ b/html.h Thu Feb 05 16:15:43 2009 -0500 @@ -4,6 +4,7 @@ #include "post.h" extern void html_story(struct post *post); +extern void html_index(struct post *post); extern void html_comments(struct post *post); extern void html_sidebar(struct post *post); extern void html_header(struct post *post);
--- a/index.c Thu Feb 05 15:59:55 2009 -0500 +++ b/index.c Thu Feb 05 16:15:43 2009 -0500 @@ -21,6 +21,7 @@ fprintf(post.out, "Content-Type: text/html\n\n"); html_header(&post); + html_index(&post); html_sidebar(&post); html_footer(&post);