Mercurial > paster
changeset 81:1ffe2f5a8500
pasterd: use HTML files to allow themes
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 17 Mar 2023 07:56:01 +0100 |
parents | 9bc744a4a292 |
children | 0a29424e4486 |
files | GNUmakefile html/footer.html html/header.html html/index.html html/new.html html/paste.html html/search.html html/status.html page-index.c page-new.c page-paste.c page-search.c page-static.c page-status.c page.c page.h themes/default/footer.html themes/default/header.html themes/default/index.html themes/default/new.html themes/default/paste.html themes/default/search.html themes/default/sourcecodepro.ttf themes/default/static/sourcecodepro.ttf themes/default/static/style.css themes/default/static/titilliumweb.ttf themes/default/status.html themes/default/style.css themes/default/titilliumweb.ttf |
diffstat | 29 files changed, 295 insertions(+), 322 deletions(-) [+] |
line wrap: on
line diff
--- a/GNUmakefile Fri Mar 17 07:46:43 2023 +0100 +++ b/GNUmakefile Fri Mar 17 07:56:01 2023 +0100 @@ -57,15 +57,6 @@ LIBPASTER_DEPS := $(LIBPASTER_SRCS:.c=.d) LIBPASTER := libpaster.a -LIBPASTER_HTML_SRCS := html/footer.html -LIBPASTER_HTML_SRCS += html/header.html -LIBPASTER_HTML_SRCS += html/index.html -LIBPASTER_HTML_SRCS += html/new.html -LIBPASTER_HTML_SRCS += html/paste.html -LIBPASTER_HTML_SRCS += html/search.html -LIBPASTER_HTML_SRCS += html/status.html -LIBPASTER_HTML_OBJS := $(LIBPASTER_HTML_SRCS:.html=.h) - LIBPASTER_SQL_SRCS := sql/clear.sql LIBPASTER_SQL_SRCS += sql/get.sql LIBPASTER_SQL_SRCS += sql/init.sql @@ -111,8 +102,8 @@ %.a: $(AR) -rc $@ $^ -$(LIBPASTER_HTML_OBJS): extern/bcc/bcc -$(LIBPASTER_SRCS): $(LIBPASTER_HTML_OBJS) $(LIBPASTER_SQL_OBJS) +$(LIBPASTER_SQL_OBJS): extern/bcc/bcc +$(LIBPASTER_SRCS): $(LIBPASTER_SQL_OBJS) $(LIBPASTER): $(LIBPASTER_OBJS) pasterd: private LDLIBS += $(KCGI_LIBS) @@ -120,7 +111,7 @@ clean: rm -f extern/bcc/bcc extern/bcc/bcc.d - rm -f $(LIBPASTER) $(LIBPASTER_OBJS) $(LIBPASTER_DEPS) $(LIBPASTER_HTML_OBJS) $(LIBPASTER_SQL_OBJS) + rm -f $(LIBPASTER) $(LIBPASTER_OBJS) $(LIBPASTER_DEPS) $(LIBPASTER_SQL_OBJS) rm -f paster pasterd pasterd.d rm -f test.db $(TESTS_OBJS) @@ -139,7 +130,6 @@ mkdir -p $(DESTDIR)$(SHAREDIR)/paster cp -R themes $(DESTDIR)$(SHAREDIR)/paster $(SED) < pasterd.8 > $(DESTDIR)$(MANDIR)/man8/pasterd.8 - $(SED) < pasterd-themes.5 > $(DESTDIR)$(MANDIR)/man5/pasterd-themes.5 install: install-pasterd install-paster
--- a/html/footer.html Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ - </section> - </body> -</html>
--- a/html/header.html Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <link rel="stylesheet" href="/static/style.css"> - <title>@@title@@</title> - </head> - - <body> - <nav id="nav"> - <ul id="nav-links"> - <li><a class="nav-link nav-link-brand" href="/">paster</a></li> - <li><a class="nav-link" href="/new">new</a></li> - <li><a class="nav-link" href="/search">search</a></li> - </ul> - </nav> - - <section id="container">
--- a/html/index.html Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ - <h1>Recent pastes</h1> - - <table> - <thead> - <tr> - <th>Name</th> - <th>Author</th> - <th>Language</th> - <th>Date</th> - <th>Expires in</th> - <tr> - </thead> - <tbody> - @@pastes@@ - </tbody> - </table>
--- a/html/new.html Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ - <h1>Create paste</h1> - - <form action="/new" method="post"> - <table> - <tr> - <td class="label">Title</td> - <td><input name="title" type="text" placeholder="Untitled" value="@@title@@" /></td> - </tr> - - <tr> - <td class="label">Author</td> - <td><input name="author" type="text" placeholder="Anonymous" value="@@author@@" /></td> - </tr> - - <tr> - <td class="label">Language</td> - <td> - <select name="language"> - @@languages@@ - </select> - </td> - </tr> - - <tr> - <td class="label">Expires in</td> - <td> - <select name="duration"> - @@durations@@ - </select> - </td> - </tr> - - <tr> - <td class="label">Public</td> - <td><input type="checkbox" name="visible"></input></td> - </tr> - </table> - - <textarea id="code" class="textarea" placeholder="What do you want to share?" rows="10" name="code">@@code@@</textarea> - <input class="submit" type="submit" value="paste" /> - </form>
--- a/html/paste.html Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ - <h1>Paste @@title@@</h1> - - <ul id="paste-menu"> - <li><a href="/fork/@@id@@">Fork</a></li> - <li><a href="/download/@@id@@">Download</a></li> - </ul> - - <table> - <tbody> - <tr> - <td class="label">Identifier</td> - <td>@@id@@</td> - </tr> - <tr> - <td class="label">Title</td> - <td>@@title@@</td> - </tr> - <tr> - <td class="label">Author</td> - <td>@@author@@</td> - </tr> - <tr> - <td class="label">Language</td> - <td>@@language@@</td> - </tr> - <tr> - <td class="label">Date</td> - <td>@@date@@</td> - </tr> - <tr> - <td class="label">Public</td> - <td>@@public@@</td> - </tr> - <tr> - <td class="label">Expires in</td> - <td>@@expires@@</td> - </tr> - </tbody> - </table> - <pre> -@@code@@ - </pre>
--- a/html/search.html Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ - <h1>Search pastes</h1> - - <form action="/search" method="post"> - <table> - <tr> - <td>Title</td> - <td><input name="title" type="text" placeholder="Title" /></td> - </tr> - - <tr> - <td>Author</td> - <td><input name="author" type="text" placeholder="Author" /></td> - </tr> - - <tr> - <td>Language</td> - <td> - <select name="language"> - @@languages@@ - </select> - </td> - </tr> - </table> - - <input class="submit" type="submit" value="Search" /> - </form>
--- a/html/status.html Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ - <h1>@@code@@ -- @@message@@</h1>
--- a/page-index.c Fri Mar 17 07:46:43 2023 +0100 +++ b/page-index.c Fri Mar 17 07:56:01 2023 +0100 @@ -25,8 +25,6 @@ #include "paste.h" #include "util.h" -#include "html/index.h" - #define LIMIT 16 #define TITLE "paster -- recent pastes" @@ -135,7 +133,7 @@ .pastesz = pastesz }; - page(req, KHTTP_200, TITLE, html_index, &self.template); + page(req, KHTTP_200, TITLE, "index.html", &self.template); } void
--- a/page-new.c Fri Mar 17 07:46:43 2023 +0100 +++ b/page-new.c Fri Mar 17 07:56:01 2023 +0100 @@ -27,8 +27,6 @@ #include "paste.h" #include "util.h" -#include "html/new.h" - #define TITLE "paster -- create a new paste" enum { @@ -190,7 +188,7 @@ .paste = paste }; - page(req, KHTTP_200, TITLE, html_new, &self.template); + page(req, KHTTP_200, TITLE, "new.html", &self.template); } void
--- a/page-paste.c Fri Mar 17 07:46:43 2023 +0100 +++ b/page-paste.c Fri Mar 17 07:56:01 2023 +0100 @@ -25,8 +25,6 @@ #include "paste.h" #include "util.h" -#include "html/paste.h" - #define TITLE "paster -- paste details" enum { @@ -115,7 +113,7 @@ if (database_get(&self.paste, req->path) < 0) page_status(req, KHTTP_404); else { - page(req, KHTTP_200, TITLE, html_paste, &self.template); + page(req, KHTTP_200, TITLE, "paste.html", &self.template); paste_finish(&self.paste); } }
--- a/page-search.c Fri Mar 17 07:46:43 2023 +0100 +++ b/page-search.c Fri Mar 17 07:56:01 2023 +0100 @@ -27,8 +27,6 @@ #include "paste.h" #include "util.h" -#include "html/search.h" - #define TITLE "paster -- search" #define LIMIT 16 @@ -83,7 +81,7 @@ } }; - page(req, KHTTP_200, TITLE, html_search, &self.template); + page(req, KHTTP_200, TITLE, "search.html", &self.template); } static void
--- a/page-static.c Fri Mar 17 07:46:43 2023 +0100 +++ b/page-static.c Fri Mar 17 07:56:01 2023 +0100 @@ -46,8 +46,7 @@ struct stat st; char path[PATH_MAX]; - /* Skip /static part that we don't want in the theme directory. */ - snprintf(path, sizeof (path), "%s%s", config.themedir, req->fullpath + 7); + snprintf(path, sizeof (path), "%s%s", config.themedir, req->fullpath); if (stat(path, &st) < 0) page_status(req, KHTTP_404);
--- a/page-status.c Fri Mar 17 07:46:43 2023 +0100 +++ b/page-status.c Fri Mar 17 07:56:01 2023 +0100 @@ -21,8 +21,6 @@ #include "page.h" #include "util.h" -#include "html/status.h" - enum { KEYWORD_CODE, KEYWORD_MESSAGE @@ -88,5 +86,5 @@ .status = status }; - page(req, status, "paster -- error", html_status, &self.template); + page(req, status, "paster -- error", "status.html", &self.template); }
--- a/page.c Fri Mar 17 07:46:43 2023 +0100 +++ b/page.c Fri Mar 17 07:56:01 2023 +0100 @@ -23,12 +23,6 @@ #include "page.h" #include "util.h" -#include "html/footer.h" -#include "html/header.h" -#include "html/status.h" - -#define CHAR(html) (const char *)(html) - enum { KEYWORD_TITLE, }; @@ -63,12 +57,12 @@ page(struct kreq *req, enum khttp status, const char *title, - const unsigned char *html, + const char *filename, const struct ktemplate *tmpl) { assert(req); assert(title); - assert(html); + assert(filename); assert(tmpl); struct page self = { @@ -85,8 +79,8 @@ khttp_head(req, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME_TEXT_HTML]); khttp_head(req, kresps[KRESP_STATUS], "%s", khttps[status]); khttp_body(req); - khttp_template_buf(req, &self.template, CHAR(html_header), strlen(CHAR(html_header))); - khttp_template_buf(req, tmpl, CHAR(html), strlen(CHAR(html))); - khttp_template_buf(req, NULL, CHAR(html_footer), strlen(CHAR(html_footer))); + khttp_template(req, &self.template, path("header.html")); + khttp_template(req, tmpl, path(filename)); + khttp_template(req, NULL, path("footer.html")); khttp_free(req); }
--- a/page.h Fri Mar 17 07:46:43 2023 +0100 +++ b/page.h Fri Mar 17 07:56:01 2023 +0100 @@ -30,7 +30,7 @@ page(struct kreq *req, enum khttp status, const char *title, - const unsigned char *html, + const char *filename, const struct ktemplate *tmpl); #endif /* !PASTER_PAGE_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/footer.html Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,3 @@ + </section> + </body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/header.html Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <link rel="stylesheet" href="/static/style.css"> + <title>@@title@@</title> + </head> + + <body> + <nav id="nav"> + <ul id="nav-links"> + <li><a class="nav-link nav-link-brand" href="/">paster</a></li> + <li><a class="nav-link" href="/new">new</a></li> + <li><a class="nav-link" href="/search">search</a></li> + </ul> + </nav> + + <section id="container">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/index.html Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,16 @@ + <h1>Recent pastes</h1> + + <table> + <thead> + <tr> + <th>Name</th> + <th>Author</th> + <th>Language</th> + <th>Date</th> + <th>Expires in</th> + <tr> + </thead> + <tbody> + @@pastes@@ + </tbody> + </table>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/new.html Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,41 @@ + <h1>Create paste</h1> + + <form action="/new" method="post"> + <table> + <tr> + <td class="label">Title</td> + <td><input name="title" type="text" placeholder="Untitled" value="@@title@@" /></td> + </tr> + + <tr> + <td class="label">Author</td> + <td><input name="author" type="text" placeholder="Anonymous" value="@@author@@" /></td> + </tr> + + <tr> + <td class="label">Language</td> + <td> + <select name="language"> + @@languages@@ + </select> + </td> + </tr> + + <tr> + <td class="label">Expires in</td> + <td> + <select name="duration"> + @@durations@@ + </select> + </td> + </tr> + + <tr> + <td class="label">Public</td> + <td><input type="checkbox" name="visible"></input></td> + </tr> + </table> + + <textarea id="code" class="textarea" placeholder="What do you want to share?" rows="10" name="code">@@code@@</textarea> + <input class="submit" type="submit" value="paste" /> + </form>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/paste.html Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,42 @@ + <h1>Paste @@title@@</h1> + + <ul id="paste-menu"> + <li><a href="/fork/@@id@@">Fork</a></li> + <li><a href="/download/@@id@@">Download</a></li> + </ul> + + <table> + <tbody> + <tr> + <td class="label">Identifier</td> + <td>@@id@@</td> + </tr> + <tr> + <td class="label">Title</td> + <td>@@title@@</td> + </tr> + <tr> + <td class="label">Author</td> + <td>@@author@@</td> + </tr> + <tr> + <td class="label">Language</td> + <td>@@language@@</td> + </tr> + <tr> + <td class="label">Date</td> + <td>@@date@@</td> + </tr> + <tr> + <td class="label">Public</td> + <td>@@public@@</td> + </tr> + <tr> + <td class="label">Expires in</td> + <td>@@expires@@</td> + </tr> + </tbody> + </table> + <pre> +@@code@@ + </pre>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/search.html Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,26 @@ + <h1>Search pastes</h1> + + <form action="/search" method="post"> + <table> + <tr> + <td>Title</td> + <td><input name="title" type="text" placeholder="Title" /></td> + </tr> + + <tr> + <td>Author</td> + <td><input name="author" type="text" placeholder="Author" /></td> + </tr> + + <tr> + <td>Language</td> + <td> + <select name="language"> + @@languages@@ + </select> + </td> + </tr> + </table> + + <input class="submit" type="submit" value="Search" /> + </form>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/static/style.css Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,132 @@ +@font-face { + font-family: titilliumweb; + src: url(/static/titilliumweb.ttf); +} + +@font-face { + font-family: sourcecodepro; + src: url(/static/sourcecodepro.ttf); +} + +* { + margin: 0; + padding: 0; + font-family: titilliumweb; + color: #212121; +} + +:root { + --main-color1: #254E70; + --main-color2: #37718E; + --main-color3: #8EE3EF; + --main-color4: #AEF3E7; + --main-color5: #C33C54; +} + +a { + color: var(--main-color1); +} + +a:hover { + color: var(--main-color2); +} + +pre, code { + padding-left: 0.5em; + padding-right: 0.5em; + background-color: gainsboro; + border-radius: 4px; + font-family: sourcecodepro; + letter-spacing: 0; + padding: 0.15em 0.25em 0.15em 0.25em; + color: #000000; +} + +pre { + margin-top: 0.5em; + margin-bottom: 0.5em; + border-left: 4px solid var(--main-color1); + box-shadow: #d9d9d9 0px 1px 4px; +} + +#nav-links { + background-color: var(--main-color1); + list-style-type: none; + display: flex; +} + +#nav .nav-link-brand { + font-weight: bold; +} + +#nav a { + text-decoration: none; + color: #ffffff; + font-size: large; + display: block; + padding: 1em; +} + +#nav a:hover { + background-color: var(--main-color2); +} + +#container { + max-width: 768px; + margin: 0 auto; + margin-top: 1em; + padding: 1em; +} + +/* + * Style for items on /paste. + */ + +#paste-menu { + list-style-type: none; + margin-top: 0.5em; + margin-bottom: 0.5em; +} + +#paste-menu li { + display: inline-block; + background-color: var(--main-color2); + border-radius: 2px; +} + +#paste-menu a { + color: #ffffff; + text-decoration: none; + padding: 0.5em; +} + +#code { + max-width: 768px; + width: 100%; +} + +.submit { + background-color: var(--main-color2); + color: #ffffff; + border: 0; + border-radius: 2px; + padding: 0.5em; + margin-top: 1em; + font-size: medium; +} + +/* + * Other generic stuff. + */ + +.label { + font-weight: bold; +} + +td, th { + padding: 0.2em; +} + +pre { + white-space: pre-line; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/default/status.html Fri Mar 17 07:56:01 2023 +0100 @@ -0,0 +1,1 @@ + <h1>@@code@@ -- @@message@@</h1>
--- a/themes/default/style.css Fri Mar 17 07:46:43 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -@font-face { - font-family: titilliumweb; - src: url(/static/titilliumweb.ttf); -} - -@font-face { - font-family: sourcecodepro; - src: url(/static/sourcecodepro.ttf); -} - -* { - margin: 0; - padding: 0; - font-family: titilliumweb; - color: #212121; -} - -:root { - --main-color1: #254E70; - --main-color2: #37718E; - --main-color3: #8EE3EF; - --main-color4: #AEF3E7; - --main-color5: #C33C54; -} - -a { - color: var(--main-color1); -} - -a:hover { - color: var(--main-color2); -} - -pre, code { - padding-left: 0.5em; - padding-right: 0.5em; - background-color: gainsboro; - border-radius: 4px; - font-family: sourcecodepro; - letter-spacing: 0; - padding: 0.15em 0.25em 0.15em 0.25em; - color: #000000; -} - -pre { - margin-top: 0.5em; - margin-bottom: 0.5em; - border-left: 4px solid var(--main-color1); - box-shadow: #d9d9d9 0px 1px 4px; -} - -#nav-links { - background-color: var(--main-color1); - list-style-type: none; - display: flex; -} - -#nav .nav-link-brand { - font-weight: bold; -} - -#nav a { - text-decoration: none; - color: #ffffff; - font-size: large; - display: block; - padding: 1em; -} - -#nav a:hover { - background-color: var(--main-color2); -} - -#container { - max-width: 768px; - margin: 0 auto; - margin-top: 1em; - padding: 1em; -} - -/* - * Style for items on /paste. - */ - -#paste-menu { - list-style-type: none; - margin-top: 0.5em; - margin-bottom: 0.5em; -} - -#paste-menu li { - display: inline-block; - background-color: var(--main-color2); - border-radius: 2px; -} - -#paste-menu a { - color: #ffffff; - text-decoration: none; - padding: 0.5em; -} - -#code { - max-width: 768px; - width: 100%; -} - -.submit { - background-color: var(--main-color2); - color: #ffffff; - border: 0; - border-radius: 2px; - padding: 0.5em; - margin-top: 1em; - font-size: medium; -} - -/* - * Other generic stuff. - */ - -.label { - font-weight: bold; -} - -td, th { - padding: 0.2em; -} - -pre { - white-space: pre-line; -}