Mercurial > paster
comparison fragment-paste.c @ 51:07b6887d3557
pasterd: split into individual pages
While here add a similar mini.css theme as in imgup.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 21 Dec 2020 18:22:44 +0100 |
parents | |
children | fba88439ec0a |
comparison
equal
deleted
inserted
replaced
50:520f57836ff3 | 51:07b6887d3557 |
---|---|
1 /* | |
2 * fragment-paste.c -- paste index renderer | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <sys/types.h> | |
20 #include <assert.h> | |
21 #include <stdarg.h> | |
22 #include <stdint.h> | |
23 #include <time.h> | |
24 | |
25 #include <kcgi.h> | |
26 #include <kcgihtml.h> | |
27 | |
28 #include "fragment-paste.h" | |
29 #include "fragment.h" | |
30 #include "paste.h" | |
31 #include "util.h" | |
32 | |
33 struct template { | |
34 struct kreq *req; | |
35 const struct paste *paste; | |
36 }; | |
37 | |
38 static const char *keywords[] = { | |
39 "author", | |
40 "date", | |
41 "expiration", | |
42 "id", | |
43 "language", | |
44 "title" | |
45 }; | |
46 | |
47 static int | |
48 template(size_t keyword, void *arg) | |
49 { | |
50 struct template *tp = arg; | |
51 struct khtmlreq html; | |
52 | |
53 khtml_open(&html, tp->req, KHTML_PRETTY); | |
54 | |
55 switch (keyword) { | |
56 case 0: | |
57 khtml_puts(&html, tp->paste->author); | |
58 break; | |
59 case 1: | |
60 khtml_puts(&html, bstrftime("%c", localtime(&tp->paste->timestamp))); | |
61 break; | |
62 case 2: | |
63 khtml_puts(&html, ttl(tp->paste->timestamp, tp->paste->duration)); | |
64 break; | |
65 case 3: | |
66 khtml_puts(&html, tp->paste->id); | |
67 break; | |
68 case 4: | |
69 khtml_puts(&html, tp->paste->language); | |
70 break; | |
71 case 5: | |
72 khtml_puts(&html, tp->paste->title); | |
73 break; | |
74 default: | |
75 break; | |
76 } | |
77 | |
78 khtml_close(&html); | |
79 | |
80 return 1; | |
81 } | |
82 | |
83 void | |
84 fragment_paste(struct kreq *r, const struct paste *paste) | |
85 { | |
86 assert(r); | |
87 assert(paste); | |
88 | |
89 struct template data = { | |
90 .req = r, | |
91 .paste = paste, | |
92 }; | |
93 struct ktemplate kt = { | |
94 .key = keywords, | |
95 .keysz = NELEM(keywords), | |
96 .cb = template, | |
97 .arg = &data | |
98 }; | |
99 | |
100 fragment(r, &kt, "fragments/paste.html"); | |
101 } |