Mercurial > blahgd
changeset 39:74c86e024fa5
feed: most of the post-atom-feed
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Fri, 13 Feb 2009 17:43:25 -0500 |
parents | 61090f874175 |
children | cae1211c3a5b |
files | .gitignore Makefile config.h feed.c html.c html.h templates/footer.atom templates/story-top.atom |
diffstat | 8 files changed, 95 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/.gitignore Thu Feb 12 11:57:35 2009 -0500 +++ b/.gitignore Fri Feb 13 17:43:25 2009 -0500 @@ -2,6 +2,7 @@ story archive category +feed tags
--- a/Makefile Thu Feb 12 11:57:35 2009 -0500 +++ b/Makefile Fri Feb 13 17:43:25 2009 -0500 @@ -3,7 +3,7 @@ FILES=sar.c post.c xattr.c html.c dir.c -all: story index archive category +all: story index archive category feed clean: rm -f story index @@ -19,3 +19,6 @@ category: category.c $(FILES) $(CC) $(CFLAGS) -o $@ category.c $(FILES) + +feed: feed.c $(FILES) + $(CC) $(CFLAGS) -o $@ feed.c $(FILES)
--- a/config.h Thu Feb 12 11:57:35 2009 -0500 +++ b/config.h Fri Feb 13 17:43:25 2009 -0500 @@ -2,6 +2,7 @@ #define __CONFIG_H #define HTML_INDEX_STORIES 10 +#define FEED_INDEX_STORIES 10 #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/feed.c Fri Feb 13 17:43:25 2009 -0500 @@ -0,0 +1,36 @@ +#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; + struct post post; + + clock_gettime(CLOCK_REALTIME, &s); + + memset(&post, 0, sizeof(struct post)); + post.out = stdout; + post.title = "Blahg"; + + fprintf(post.out, "Content-Type: application/atom+xml; charset=UTF-8\n\n"); + + feed_header(&post,"atom"); + feed_index(&post,"atom"); + feed_footer(&post,"atom"); + + post.title = NULL; + 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 12 11:57:35 2009 -0500 +++ b/html.c Fri Feb 13 17:43:25 2009 -0500 @@ -112,6 +112,43 @@ closedir(dir); } +static void __each_feed_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.atom", repltab_story_html); + //__invoke_for_each_post_cat(&p, __story_cat_item); + cat(&p, NULL, "templates/story-middle-desc.atom", repltab_story_html); + //cat_post_preview(&p); + cat(&p, NULL, "templates/story-bottom-desc.atom", repltab_story_html); + cat(&p, NULL, "templates/story-middle.atom", repltab_story_html); + //cat_post(&p); + cat(&p, NULL, "templates/story-bottom.atom", NULL); + + destroy_post(&p); +} + +void feed_index(struct post *post, char *fmt) +{ + DIR *dir; + + dir = opendir("data/posts"); + if (!dir) + return; + + sorted_readdir_loop(dir, post, __each_feed_index_helper, NULL, SORT_DESC, + FEED_INDEX_STORIES); + + closedir(dir); +} + /************************************************************************/ /* ARCHIVE INDEX */ /************************************************************************/ @@ -272,6 +309,11 @@ cat(post, NULL, "templates/header.html", repltab_story_html); } +void feed_header(struct post *post, char *fmt) +{ + cat(post, NULL, "templates/header.atom", repltab_story_html); +} + /************************************************************************/ /* PAGE FOOTER */ /************************************************************************/ @@ -279,3 +321,8 @@ { cat(post, NULL, "templates/footer.html", repltab_story_html); } + +void feed_footer(struct post *post, char *fmt) +{ + cat(post, NULL, "templates/footer.atom", repltab_story_html); +}
--- a/html.h Thu Feb 12 11:57:35 2009 -0500 +++ b/html.h Fri Feb 13 17:43:25 2009 -0500 @@ -12,4 +12,8 @@ extern void html_header(struct post *post); extern void html_footer(struct post *post); +extern void feed_index(struct post *post, char *fmt); +extern void feed_header(struct post *post, char *fmt); +extern void feed_footer(struct post *post, char *fmt); + #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/footer.atom Fri Feb 13 17:43:25 2009 -0500 @@ -0,0 +1,1 @@ +</feed>
--- a/templates/story-top.atom Thu Feb 12 11:57:35 2009 -0500 +++ b/templates/story-top.atom Fri Feb 13 17:43:25 2009 -0500 @@ -11,4 +11,4 @@ <link rel="replies" type="text/html" href="http://josefsipek.net/blahg-test/?p=@@POSTID@@#comments" thr:count="1"/> <link rel="replies" type="application/atom+xml" href="http://josefsipek.net/blahg-test/?feed=atom&p=@@POSTID@@" thr:count="1"/> - <thr:total>1</thr:total> + <thr:total>0</thr:total> <!-- FIXME: number of comments -->