#include #include #include #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[] = "\ \n\ \n\ Posts\n\ \n\ \n\ \n\ \n\ \"PreviousPlan!\n\ \n\

List of posts

\n\ "; static char footer[] = "\
\n\ \"EMAIL\"/\n\

Webmaster email: erikk@previousplan.org \ (PGP key)

\n\ \n\ \n\ "; char title[128], link[CLEN]; char *item[] = { "
  • ", title, "
  • \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 ? "\n

    %B %Y

    \n
      \n" : "

      %B %Y

      \n
        \n", tm); xfputs(dateheader, outf); } memcpy(&lasttm, tm, sizeof(lasttm)); for (j = 0; j < LEN(item); j++) xfputs(item[j], outf); } if (ndoc) xfputs("
      \n", outf); xfputs(footer, outf); fclose(outf); }