Blob


1 {!
2 /*
3 * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 #include <sys/queue.h>
19 #include <sys/tree.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
24 #include <event.h>
25 #include <limits.h>
26 #include <stdint.h>
27 #include <string.h>
29 #include "galileo.h"
31 !}
33 {{ define tp_head(struct template *tp, const char *lang,
34 const char *stylesheet) }}
35 <!doctype html>
36 <html{{ if *lang != '\0' }}lang="{{ lang }}"{{ end }}>
37 <head>
38 <meta name="viewport" content="initial-scale=1" />
39 {{ if *stylesheet != '\0' }}
40 <link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
41 {{ end }}
42 </head>
43 <body>
44 {{ end }}
46 {{ define tp_foot(struct template *tp) }}
47 {! struct client *clt = tp->tp_arg; !}
48 {! struct proxy_config *pc = clt->clt_pc; !}
49 {! const char *host = pc->proxy_name; !}
50 {! const char *path = clt->clt_path_info; !}
52 <footer>
53 <hr />
54 <dl>
55 <dt>Original URL:</dt>
56 <dd>
57 <a href="gemini://{{ host | urlescape }}{{ path | urlescape }}">
58 gemini://{{ host }}{{ path }}
59 </a>
60 </dd>
61 </dl>
62 </footer>
63 </body>
64 </html>
65 {{ end }}
67 {{ define tp_figure(struct template *tp, const char *url,
68 const char *label) }}
69 {!
70 struct client *clt = tp->tp_arg;
71 const char *path = "";
72 int relativify;
74 relativify = *url == '/' || strstr(url, "//") == NULL;
75 if (relativify) {
76 path = clt->clt_script_name;
77 url++; /* skip leading / */
78 }
79 !}
80 <figure>
81 <a href="{{ path | urlescape }}{{ url | urlescape }}">
82 <img src="{{ path | urlescape }}{{ url }}" />
83 </a>
84 <figcaption>
85 {{ label }}
86 </figcaption>
87 </figure>
88 {{ end }}