From: Bernhard Reutner-Fischer <[email protected]>

Allow to specify an alternative text for the logo image.
Fix empty logo-link while at it.

Signed-off-by: Bernhard Reutner-Fischer 
<[email protected]>
---
 cgit.c       |   15 +++++++++++++--
 cgit.h       |    2 ++
 cgitrc.5.txt |   18 +++++++++++++-----
 ui-shared.c  |   31 +++++++++++++++++++++++--------
 4 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/cgit.c b/cgit.c
index ae413c6..718b531 100644
--- a/cgit.c
+++ b/cgit.c
@@ -80,6 +80,8 @@ static void repo_config(struct cgit_repo *repo, const char 
*name, const char *va
                string_list_append(&repo->readme, xstrdup(value));
        } else if (!strcmp(name, "logo") && value != NULL)
                repo->logo = xstrdup(value);
+       else if (!strcmp(name, "logo-alt") && value != NULL)
+               repo->logo_alt = xstrdup(value);
        else if (!strcmp(name, "logo-link") && value != NULL)
                repo->logo_link = xstrdup(value);
        else if (ctx.cfg.enable_filter_overrides) {
@@ -128,12 +130,14 @@ static void config_cb(const char *name, const char *value)
                ctx.cfg.head_include = xstrdup(value);
        else if (!strcmp(name, "header"))
                ctx.cfg.header = xstrdup(value);
-       else if (!strcmp(name, "logo"))
-               ctx.cfg.logo = xstrdup(value);
        else if (!strcmp(name, "index-header"))
                ctx.cfg.index_header = xstrdup(value);
        else if (!strcmp(name, "index-info"))
                ctx.cfg.index_info = xstrdup(value);
+       else if (!strcmp(name, "logo"))
+               ctx.cfg.logo = xstrdup(value);
+       else if (!strcmp(name, "logo-alt"))
+               ctx.cfg.logo_alt = xstrdup(value);
        else if (!strcmp(name, "logo-link"))
                ctx.cfg.logo_link = xstrdup(value);
        else if (!strcmp(name, "module-link"))
@@ -356,6 +360,7 @@ static void prepare_context(void)
        ctx.cfg.commit_sort = 0;
        ctx.cfg.css = "/cgit.css";
        ctx.cfg.logo = "/cgit.png";
+       ctx.cfg.logo_alt = "cgit logo";
        ctx.cfg.favicon = "/favicon.ico";
        ctx.cfg.local_time = 0;
        ctx.cfg.enable_http_clone = 1;
@@ -837,6 +842,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
                        cgit_find_stats_periodname(repo->max_stats));
        if (repo->logo)
                fprintf(f, "repo.logo=%s\n", repo->logo);
+       if (repo->logo_alt)
+               fprintf(f, "repo.logo-alt=%s\n", repo->logo_alt);
        if (repo->logo_link)
                fprintf(f, "repo.logo-link=%s\n", repo->logo_link);
        fprintf(f, "repo.enable-remote-branches=%d\n", 
repo->enable_remote_branches);
@@ -1062,6 +1069,10 @@ int main(int argc, const char **argv)
        if (!ctx.cfg.virtual_root && ctx.cfg.script_name)
                ctx.cfg.virtual_root = ensure_end(ctx.cfg.script_name, '/');
 
+       /* Now we can set the default global logo-link unless specified */
+       if (!ctx.cfg.logo_link)
+               ctx.cfg.logo_link = (char *)cgit_rooturl();
+
        /* If no url parameter is specified on the querystring, lets
         * use PATH_INFO as url. This allows cgit to work with virtual
         * urls without the need for rewriterules in the webserver (as
diff --git a/cgit.h b/cgit.h
index 16f8092..27167bb 100644
--- a/cgit.h
+++ b/cgit.h
@@ -89,6 +89,7 @@ struct cgit_repo {
        char *section;
        char *clone_url;
        char *logo;
+       char *logo_alt;
        char *logo_link;
        int snapshots;
        int enable_commit_graph;
@@ -195,6 +196,7 @@ struct cgit_config {
        char *index_header;
        char *index_info;
        char *logo;
+       char *logo_alt;
        char *logo_link;
        char *mimetype_file;
        char *module_link;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 0a2a402..4a9c68f 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -242,10 +242,14 @@ logo::
        Url which specifies the source of an image which will be used as a logo
        on all cgit pages. Default value: "/cgit.png".
 
+logo-alt::
+       Alternate text of the logo image. Default value: "cgit logo".
+
 logo-link::
        Url loaded when clicking on the cgit logo image. If unspecified the
-       calculated url of the repository index page will be used. Default
-       value: none.
+       calculated url of the repository index page will be used.
+       If empty, no URL is emitted.
+       Default value: none.
 
 owner-filter::
        Specifies a command which will be invoked to format the Owner
@@ -524,10 +528,14 @@ repo.logo::
        Url which specifies the source of an image which will be used as a logo
        on this repo's pages. Default value: global logo.
 
+repo.logo-alt::
+       Alternate text of the logo image. Default value: global logo-alt.
+
 repo.logo-link::
        Url loaded when clicking on the cgit logo image. If unspecified the
-       calculated url of the repository index page will be used. Default
-       value: global logo-link.
+       calculated url of the repository index page will be used.
+       If empty, no URL is emitted.
+       Default value: global logo-link.
 
 repo.owner-filter::
        Override the default owner-filter. Default value: none. See also:
@@ -804,7 +812,7 @@ favicon=/favicon.ico
 
 # Use a custom logo
 logo=/img/mylogo.png
-
+logo-alt=my img alt text
 
 # Enable statistics per week, month and quarter
 max-stats=quarter
diff --git a/ui-shared.c b/ui-shared.c
index ac5a287..8334739 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -860,7 +860,8 @@ static void cgit_print_path_crumbs(char *path)
 
 static void print_header(void)
 {
-       char *logo = NULL, *logo_link = NULL;
+       char *logo = NULL, *logo_alt = NULL, *logo_link = NULL;
+       unsigned int any_logo_link;
 
        html("<table id='header'>\n");
        html("<tr>\n");
@@ -869,19 +870,33 @@ static void print_header(void)
                logo = ctx.repo->logo;
        else
                logo = ctx.cfg.logo;
-       if (ctx.repo && ctx.repo->logo_link && *ctx.repo->logo_link)
+       if (ctx.repo && ctx.repo->logo_alt && *ctx.repo->logo_alt)
+               logo_alt = ctx.repo->logo_alt;
+       else
+               logo_alt = ctx.cfg.logo_alt;
+       if (ctx.repo && ctx.repo->logo_link)
                logo_link = ctx.repo->logo_link;
        else
                logo_link = ctx.cfg.logo_link;
+       any_logo_link = logo_link && *logo_link;
+
        if (logo && *logo) {
-               html("<td class='logo' rowspan='2'><a href='");
-               if (logo_link && *logo_link)
+               html("<td class='logo' rowspan='2'>");
+               if (any_logo_link) {
+                       html("<a href='");
                        html_attr(logo_link);
-               else
-                       html_attr(cgit_rooturl());
-               html("'><img src='");
+                       html("'>");
+               }
+               html("<img src='");
                html_attr(logo);
-               html("' alt='cgit logo'/></a></td>\n");
+               if (logo_alt && *logo_alt) {
+                       html("' alt='");
+                       html_attr(logo_alt);
+               }
+               html("'/>");
+               if (any_logo_link)
+                       html("</a>");
+               html("</td>\n");
        }
 
        html("<td class='main'>");
-- 
1.7.10.4

_______________________________________________
CGit mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to