mobley

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

commit a7511ff06dda99d98594a2ecf9ef19281fe1d7af
parent a62a8c6375815f5a791cdf3c36850ae685c122a1
Author: Louis Solofrizzo <lsolofrizzo@online.net>
Date:   Mon, 17 Dec 2018 16:24:03 +0100

Add repository sort in configuration, some style fixes

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

Diffstat:
Mconfig.c | 8++++++++
Mconfig.yaml | 3++-
Mhtml.c | 2++
Mhtml.h | 1+
Mindex.c | 36++++++++++++++++++++----------------
Mmobley.h | 1+
Mrepository.h | 34+++++++++++++++++-----------------
Mstyle/main.css | 27+++++++++++++++++++++++----
8 files changed, 74 insertions(+), 38 deletions(-)

diff --git a/config.c b/config.c @@ -54,6 +54,11 @@ static bool config_read_token(const char *tok, unsigned char *value, mobley_t *c is_token = (is_token ? false : true); } + else if (strcmp(tok, "sort_repo") == 0) + { + if (strcmp((char *)value, "true") == 0) + ctx->conf.sort_repo = true; + } else { printf("Unknown token = %s\n", tok); @@ -147,6 +152,9 @@ static bool config_read_repositories(yaml_parser_t *parser, yaml_event_t *event, } while (quit != 2); free(token); + if (ctx->conf.sort_repo) + list_sort(NULL, &ctx->repos.repos, &repository_name_cmp); + return true; end: free(repo); diff --git a/config.yaml b/config.yaml @@ -5,6 +5,7 @@ logo : logo.png desc : Software Stuff title : git:// repo_dir : /tmp/git +sort_repo : true styles: - main.css @@ -57,7 +58,7 @@ repositories: owner : louis - dir : C_Advanced_Tips_n_Tricks.git - name : C advanced tips and tricks + name : C_advanced_tips_and_tricks description : 42 conference about some C tricks owner : louis diff --git a/html.c b/html.c @@ -68,6 +68,8 @@ void _html(server_req_t *r, const mobley_t *ctx, const char *b, const char *d, evbuffer_add_printf(r->req->buffer_out, " lang=\"%s\"", a->lang); if (a->charset != NULL) evbuffer_add_printf(r->req->buffer_out, " charset=\"%s\"", a->charset); + if (a->align != NULL) + evbuffer_add_printf(r->req->buffer_out, " align=\"%s\"", a->align); if (d == NULL) goto closing; diff --git a/html.h b/html.h @@ -31,6 +31,7 @@ typedef struct { const char *lang; const char *charset; const char *id; + const char *align; bool closing_slash; bool is_static; } html_args_t; diff --git a/index.c b/index.c @@ -23,24 +23,28 @@ bool index_route_handler(const mobley_t *ctx, server_req_t *r) html_open("table") { - html_open("tr") { - html("th", "Name"); - html("th", "Description"); - html("th", "Owner"); - html("th", "Last commit"); - } html_close("tr"); - - list_for_each_entry(repo, &ctx->repos.repos, node) - { + html_open("thead") { html_open("tr") { - html_open("td") { - html("a", repo->name, .href = repo->name); - } html_close("td"); - html("td", repo->desc); - html("td", repo->owner); - html("td", repo->path); + html("td", "Name"); + html("td", "Description"); + html("td", "Owner", .align = "right"); + html("td", "Last commit", .align = "right"); } html_close("tr"); - } + } html_close("thead"); + + html_open("tbody") { + list_for_each_entry(repo, &ctx->repos.repos, node) + { + html_open("tr") { + html_open("td") { + html("a", repo->name, .href = repo->name); + } html_close("td"); + html("td", repo->desc); + html("td", repo->owner, .align = "right"); + html("td", repo->path, .align = "right"); + } html_close("tr"); + } + } html_close("tbody"); } html_close("table"); return true; diff --git a/mobley.h b/mobley.h @@ -33,6 +33,7 @@ typedef struct { char *logo; char *root_desc; char *title; + bool sort_repo; list_head_t styles; } conf; diff --git a/repository.h b/repository.h @@ -28,25 +28,14 @@ typedef struct { list_head_t node; } repository_t; -/*static inline bool repository_init(repository_t *out, const char *name)*/ -//{ - //bool ret = false; - - //out->name = strdup(name); - //if (out->name == NULL) - //goto end; - - //ret = true; -//end: - //return ret; -/*}*/ - -static inline void repoitory_dtr(repository_t *ptr) +static inline void repository_dtr(repository_t *ptr) { if (ptr == NULL) return ; free(ptr->name); + free(ptr->desc); + free(ptr->owner); } static inline void repository_set_path(repository_t *out, const char *dir, const char *path) @@ -60,11 +49,22 @@ static inline void repository_list_free(list_head_t *head) list_for_each_entry_safe(node, tmp, head, node) { - free(node->desc); - free(node->name); - free(node->owner); + repository_dtr(node); free(node); } } +static inline int repository_name_cmp(void *u, list_head_t *a, list_head_t *b) +{ + repository_t *one = list_entry(a, repository_t, node); + repository_t *two = list_entry(b, repository_t, node); + + if (one->name == NULL) + return 1; + if (two->name == NULL) + return -1; + + return strcmp(one->name, two->name); +} + #endif /* REPOSITORY_H */ diff --git a/style/main.css b/style/main.css @@ -1,6 +1,9 @@ +@import url('https://fonts.googleapis.com/css?family=Inconsolata'); + html, body { margin: 0; padding: 0; + font-family: 'Inconsolata', monospace; } body { @@ -8,6 +11,7 @@ body { color: #999; height: 100%; width: 100%; + font-size: 15px; } .desc { @@ -69,15 +73,16 @@ a:hover { .header .menu { margin-left: 400px; - display: block; - margin-top: -28px; + display: table; + margin-top: -27px; font-size: 15px; - width: calc(100% - 400px); + width: auto; } .header .menu li { - display: inline-block; + display: table-cell; padding: 0 0.4em; + vertical-align: middle; } #content { @@ -88,3 +93,17 @@ table { width: 100%; text-align: left; } + +table td { + padding: 0 0.4em; + vertical-align: top; + white-space: nowrap; +} + +tr:hover td { + background-color: #333; +} + +table thead td { + font-weight: bold; +}