summaryrefslogtreecommitdiffstats
path: root/posts.c
diff options
context:
space:
mode:
Diffstat (limited to 'posts.c')
-rw-r--r--posts.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/posts.c b/posts.c
new file mode 100644
index 0000000..239f118
--- /dev/null
+++ b/posts.c
@@ -0,0 +1,93 @@
+#include <stdlib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "sm.h"
+#include "util.h"
+
+extern char kcontentdir[];
+extern char kpostsexport[];
+
+static void postsexport(Document **, int);
+
+Plugin posts = {"posts", postsexport, NULL, 0};
+
+static int
+creatcompar(const Document **d1, const Document **d2)
+{
+ return (*d2)->creat - (*d1)->creat;
+}
+
+static void
+postsexport(Document **doc, int ndoc)
+{
+ struct tm *tm, lasttm;
+ char dateheader[64];
+ FILE *outf;
+ int i, j;
+
+ static char header[] = "\
+<!DOCTYPE html>\n\
+<html>\n\
+ <title>Posts</title>\n\
+ <meta charset=\"utf-8\"/>\n\
+ <style>\n\
+ h1, nav { text-align: center }\n\
+ p { margin-left: 6%; margin-right: 6% }\n\
+ </style>\n\
+</head>\n\
+<body bgcolor=\"#000000\" background=\"/pix/crackblk.jpg\" text=\"#eeeeee\" \
+link=\"orange\" alink=\"red\" vlink=\"red\">\n\
+ <a href=\"https://previousplan.org\"><img src=\"/pix/previousplan-button.gif\" alt=\"PreviousPlan! web button\" title=\"PreviousPlan! web button\"></a>\n\
+ <nav>\n\
+ <img src=\"/pix/s-spin.gif\"/>\n\
+ <i><font size=\"6\" color=\"gold\">Previous Plan!</font></i>\n\
+ -\n\
+ <a href=\"/about.html\">Home</a>\n\
+ -\n\
+ <a href=\"/posts.html\">Posts</a>\n\
+ -\n\
+ <a href=\"/rss.xml\">RSS</a>\n\
+ -\n\
+ <a href=\"/donate.html\">Donate</a>\n\
+ <img src=\"/pix/s-spin.gif\"/>\n\
+ </nav>\n\
+ <h2>List of posts</h2>\n\
+";
+
+ static char footer[] = "\
+ <hr/>\n\
+ <img src=\"pix/s-mail.gif\" alt=\"EMAIL\"/>\n\
+ <p>Webmaster email: <a \
+href=\"mailto:erikk@previousplan.org\">erikk@previousplan.org</a> \
+<a href=\"/erikk.asc\">(PGP key)</a></p>\n\
+</body>\n\
+</html>\n\
+";
+
+ char title[128], link[CLEN];
+ char *item[] = { " <li><a href=\"", link, "\">", title, "</a></li>\n" };
+
+ qsort(doc, ndoc, sizeof(*doc), (int (*)(const void *, const void *))creatcompar);
+
+ outf = xfopen(kpostsexport, "w");
+ xfputs(header, outf);
+ for (i = 0; i < ndoc; i++) {
+ my_strlcpy(title, doc[i]->title, sizeof(title));
+ my_strlcpy(link, doc[i]->link, sizeof(link));
+
+ tm = gmtime(&doc[i]->creat);
+ if (i == 0 || tm->tm_mon != lasttm.tm_mon || tm->tm_year != lasttm.tm_year) {
+ strftime(dateheader, sizeof(dateheader), i != 0 ? "</ul>\n<h3>%B %Y</h3>\n<ul>\n" : "<h3>%B %Y</h3>\n<ul>\n", tm);
+ xfputs(dateheader, outf);
+ }
+ memcpy(&lasttm, tm, sizeof(lasttm));
+ for (j = 0; j < LEN(item); j++)
+ xfputs(item[j], outf);
+ }
+ if (ndoc)
+ xfputs("</ul>\n", outf);
+ xfputs(footer, outf);
+ fclose(outf);
+}