From b2fada1dd19211d71e04557653d08e697134a6ce Mon Sep 17 00:00:00 2001 From: Erik K Date: Fri, 13 May 2022 17:24:26 +0000 Subject: initial commit --- rss.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 rss.c (limited to 'rss.c') diff --git a/rss.c b/rss.c new file mode 100644 index 0000000..e0f22fe --- /dev/null +++ b/rss.c @@ -0,0 +1,84 @@ +#include + +#include "config.h" +#include "sm.h" +#include "util.h" + +extern char kcontentdir[]; +extern char krssexport[]; +extern char krsstitle[]; +extern char krssdescription[]; +extern char krsslink[]; + +static void rssexport(Document **, int); + +Plugin rss = {"rss", rssexport, NULL, 0}; + +static int +creatcompar(const Document **d1, const Document **d2) +{ + return (*d2)->creat - (*d1)->creat; +} + +static void +rssexport(Document **doc, int ndoc) +{ + char inpath[512]; + FILE *outf; + int i, j; + + char *header[] = { "\ +\n\ +\n\ +\n\ +\n\ +", krsstitle, "\n\ +", krssdescription, "\n\ +en-us\n\ +", krsslink, "\n\ +sm-"VERSION"\n\ +\n\ +" }; + + char *footer[] = { "\ +\n\ +\n\ +" }; + + char filename[64], title[128], creat[64], link[CLEN]; + char *itemheader[] = { "\ +\n\ + ", title, "\n\ + ", filename, "\n\ + ", creat, "\n\ + ", link, "\n\ + \n\ +\n\ +" }; + + qsort(doc, ndoc, sizeof(*doc), (int (*)(const void *, const void *))creatcompar); + + outf = xfopen(krssexport, "w"); + for (j = 0; j < LEN(header); j++) + xfputs(header[j], outf); + for (i = 0; i < ndoc; i++) { + snprintf(inpath, sizeof(inpath), "%s/%s", kcontentdir, + doc[i]->filename); + my_strlcpy(filename, doc[i]->filename, sizeof(filename)); + my_strlcpy(title, doc[i]->title, sizeof(title)); + strftime(creat, sizeof(creat), "%a, %d %b %Y %H:%M:%S %z", + gmtime(&doc[i]->creat)); + my_strlcpy(link, doc[i]->link, sizeof(link)); + for (j = 0; j < LEN(itemheader); j++) + xfputs(itemheader[j], outf); + cat(inpath, outf); + for (j = 0; j < LEN(itemfooter); j++) + xfputs(itemfooter[j], outf); + } + for (j = 0; j < LEN(footer); j++) + xfputs(footer[j], outf); + fclose(outf); +} -- cgit v1.2.3