mobley

C Git HTTP server
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/mobley

commit 4330c3d2718d73074a1f4ea8a59d99218ab354fc
parent 19d132a19f6baa74a347be7764afeffd72173d82
Author: Louis Solofrizzo <lsolofrizzo@online.net>
Date:   Sat, 15 Dec 2018 03:52:20 +0100

Add basic root menu and style

Signed-off-by: Louis Solofrizzo <lsolofrizzo@online.net>

Diffstat:
Mhtml.c | 9+++++++--
Mhtml.h | 1+
Mmain.c | 4+++-
Mmobley.h | 6+++++-
Mstatic.c | 4+++-
Astyle/main.css | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtemplate.c | 95++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
7 files changed, 194 insertions(+), 6 deletions(-)

diff --git a/html.c b/html.c @@ -27,7 +27,7 @@ void _html(server_req_t *r, const mobley_t *ctx, const char *b, const char *d, evbuffer_add_printf(r->req->buffer_out, " href=\"http://%s:%d%s\"", ctx->ip, ctx->port, a->href); } - else if (strncmp(a->href, "http", sizeof("http") -1) == 0) + else if (strncmp(a->href, "http", sizeof("http") - 1) == 0) { evbuffer_add_printf(r->req->buffer_out, " href=\"%s\"", a->href); } @@ -49,7 +49,12 @@ void _html(server_req_t *r, const mobley_t *ctx, const char *b, const char *d, if (a->type != NULL) evbuffer_add_printf(r->req->buffer_out, " type=\"%s\"", a->type); if (a->src != NULL) - evbuffer_add_printf(r->req->buffer_out, " src=\"%s\"", a->src); + { + if (a->is_static) + evbuffer_add_printf(r->req->buffer_out, " src=\"/static/%s\"", a->src); + else + evbuffer_add_printf(r->req->buffer_out, " src=\"%s\"", a->src); + } if (a->title != NULL) evbuffer_add_printf(r->req->buffer_out, " title=\"%s\"", a->title); if (a->lang != NULL) diff --git a/html.h b/html.h @@ -31,6 +31,7 @@ typedef struct { const char *lang; const char *charset; bool closing_slash; + bool is_static; } html_args_t; void _html(server_req_t *r, const mobley_t *ctx, diff --git a/main.c b/main.c @@ -96,7 +96,9 @@ static bool mobley_options(mobley_t *ctx) else ctx->port = DEFAULT_PORT; - ctx->static_dir = "/usr/local/share/mobley/"; + ctx->conf.static_dir = "/usr/local/share/mobley/"; + ctx->conf.logo = "logo.png"; + ctx->conf.root_desc = "Software Stuff"; return true; } diff --git a/mobley.h b/mobley.h @@ -27,7 +27,11 @@ typedef struct { const char *ip; uint16_t port; - const char *static_dir; + struct { + const char *static_dir; + const char *logo; + const char *root_desc; + } conf; struct event_base *evbase; struct evhtp *htp; diff --git a/static.c b/static.c @@ -19,6 +19,8 @@ static void static_set_content_type(server_req_t *r, const char *path) { if (is_ext(path, ".css")) server_req_set_content_type(r, "text/css"); + if (is_ext(path, ".png")) + server_req_set_content_type(r, "image/png"); } static bool static_send_file(server_req_t *r, const char *path) @@ -49,7 +51,7 @@ bool static_route_handler(const mobley_t *ctx, server_req_t *r) char *cur = path; char *end = path + sizeof(path); - cur += snprintf(path, end - cur, "%s", ctx->static_dir); + cur += snprintf(path, end - cur, "%s", ctx->conf.static_dir); list_for_each_entry(node, &r->uri, node) cur += snprintf(cur, end - cur, "/%s", node->val); diff --git a/style/main.css b/style/main.css @@ -0,0 +1,81 @@ +html, body { + margin: 0; + padding: 0; +} + +body { + background: #101010; + color: #999; + height: 100%; + width: 100%; +} + +.desc { + color: #777; +} + +hr { + border: 0; + border-top: 1px solid #777 +} + +a { + text-decoration: none; + color: #b5e853; +} + +a:hover { + text-decoration: underline; +} + +.header { + margin: 0; + padding: 0; + width: 100%; + height: 10%; +} + +.header ul { + margin: 0; + padding: 0; + list-style: none; + display: table-row; + width: 100%; + height: 100%; +} + +.header ul li { + display: table-cell; + vertical-align: middle; + padding: 0; + margin: 0; + height: 100%; +} + +.header .logo { + height: 100%; + padding-right: 10px; +} + +.header .logo img { + width: 400px; + height: auto; +} + +.header ul li span { + display: block; + margin-top: 5px; +} + +.header .menu { + margin-left: 400px; + display: block; + margin-top: -28px; + font-size: 15px; + width: calc(100% - 400px); +} + +.header .menu li { + display: inline-block; + padding: 0 0.4em; +} diff --git a/template.c b/template.c @@ -42,6 +42,93 @@ static void template_meta(const mobley_t *ctx, server_req_t *r) ); } +void template_header(const mobley_t *ctx, server_req_t *r) +{ + html_open("ul") { + html_open("li class='logo'") { + html_nd("img", + .src = ctx->conf.logo, + .closing_slash = true, + .class = "logo", + .is_static = true + ); + } html_close("li"); + + if (r->route == NULL) + { + html_open("li") { + html("b", "Repositories"); + html_simple("br"); + html("span", ctx->conf.root_desc, .class = "desc"); + } html_close("li"); + } + else + { + html_open("li") { + html("h3", "test_repo"); + } html_close("li"); + + html_open("li") { + html("span", "repo desc", .class = "repo-desc"); + } html_close("li"); + } + } html_close("ul"); +} + +typedef struct { + const char *name; + const char *link; +} menu_entry_t; + +static void template_menu(const mobley_t *ctx, server_req_t *r) +{ + menu_entry_t global_menu[] = { + { "Git", "/" }, + { "Builds", "/~builds" }, + { "Issues", "/~issues" }, + { "Documentation", "/~man" }, + { "Meta", "/~meta" }, + }; + + menu_entry_t repo_menu[] = { + { "Summary", "summary" }, + { "Commits", "commits" }, + { "Branches", "branches" }, + { "Releases", "releases" }, + { "Issues", "issues" }, + { "LICENSE", "license" } + }; + + + html_open("ul class='menu'") { + if (r->route == NULL) + { + STATIC_ARRAY_FOREACH_I(i, const menu_entry_t *entry, global_menu) + { + html_open("li") { + html("a", entry->name, .href = entry->link); + } html_close("li"); + + if (i + 1 < COUNT_OF(global_menu)) + html_raw("|"); + } + } + else + { + STATIC_ARRAY_FOREACH(const menu_entry_t *entry, repo_menu) + { + html_open("li") { + html("a", entry->name, .href = entry->link); + } html_close("li"); + + html_raw("|"); + } + + /* Clone */ + } + } html_close("ul"); +} + void template_begin(const mobley_t *ctx, server_req_t *r) { html_simple("!DOCTYPE html"); @@ -61,7 +148,13 @@ void template_begin(const mobley_t *ctx, server_req_t *r) } html_close("head"); - html_open("body"); + html_open("body") { + html_nd("div", .class = "header") { + template_header(ctx, r); + template_menu(ctx, r); + } html_close("div"); + html_nd("hr", .closing_slash = true); + } } }