summaryrefslogtreecommitdiffstats
path: root/skull.c
blob: 5c44f2050699dcb924c5f871bc0943d5c53d2fd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#include "sm.h"
#include "util.h"

extern char kcontentdir[];
extern char kskullexport[];

static void skullexport(Document **, int);

Plugin skull = {"skull", skullexport, NULL, 0};

static void
skullexport(Document **doc, int ndoc)
{
	char path[512], outpath[512];
	FILE *outf;
	int i, j;

	char title[128], creat[64], mod[64];
	char *header[] = { "\
<!DOCTYPE html>\n\
<html>\n\
  <title>", title, "</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\
" };

	char *footer[] = { "\
  <hr/>\n\
  <p>Written: ", creat, ", Last modified: ", mod, "</p>\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\
" };

	for (i = 0; i < ndoc; i++) {
		snprintf(path, sizeof(path), "%s/%s", kcontentdir, doc[i]->filename);
		snprintf(outpath, sizeof(outpath), "%s/%s", kskullexport, doc[i]->filename);

		if ((outf = fopen(outpath, "w")) == NULL) {
			fprintf(stderr, "%s: %s\n", outpath, strerror(errno));
			continue;
		}

		my_strlcpy(title, doc[i]->title, sizeof(title));
		strftime(creat, sizeof(creat), "%a, %Y %b %d", gmtime(&doc[i]->creat));
		strftime(mod, sizeof(mod), "%a, %Y %b %d", gmtime(&doc[i]->mod));
		for (j = 0; j < LEN(header); j++)
			xfputs(header[j], outf);
		cat(path, outf);
		for (j = 0; j < LEN(footer); j++)
			xfputs(footer[j], outf);
		fclose(outf);
	}
}