From b2fada1dd19211d71e04557653d08e697134a6ce Mon Sep 17 00:00:00 2001 From: Erik K Date: Fri, 13 May 2022 17:24:26 +0000 Subject: initial commit --- posts.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 posts.c (limited to 'posts.c') 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 +#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); +} -- cgit v1.2.3