config: add js

Just like the config allows setting css URL path, add a config for
setting the js URL path

Signed-off-by: Andy Green <andy@warmcat.com>
Reviewed-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
Andy Green 2018-06-23 18:25:53 +08:00 committed by Jason A. Donenfeld
parent 093ac96970
commit aee39b4e9a
6 changed files with 33 additions and 0 deletions

View File

@ -87,6 +87,7 @@ install: all
$(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
$(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
$(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
$(INSTALL) -m 0644 cgit.js $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js
$(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
$(INSTALL) -m 0644 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico $(INSTALL) -m 0644 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico
$(INSTALL) -m 0644 robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt $(INSTALL) -m 0644 robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt

2
cgit.c
View File

@ -143,6 +143,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.root_readme = xstrdup(value); ctx.cfg.root_readme = xstrdup(value);
else if (!strcmp(name, "css")) else if (!strcmp(name, "css"))
string_list_append(&ctx.cfg.css, xstrdup(value)); string_list_append(&ctx.cfg.css, xstrdup(value));
else if (!strcmp(name, "js"))
string_list_append(&ctx.cfg.js, xstrdup(value));
else if (!strcmp(name, "favicon")) else if (!strcmp(name, "favicon"))
ctx.cfg.favicon = xstrdup(value); ctx.cfg.favicon = xstrdup(value);
else if (!strcmp(name, "footer")) else if (!strcmp(name, "footer"))

1
cgit.h
View File

@ -264,6 +264,7 @@ struct cgit_config {
int branch_sort; int branch_sort;
int commit_sort; int commit_sort;
struct string_list mimetypes; struct string_list mimetypes;
struct string_list js;
struct cgit_filter *about_filter; struct cgit_filter *about_filter;
struct cgit_filter *commit_filter; struct cgit_filter *commit_filter;
struct cgit_filter *source_filter; struct cgit_filter *source_filter;

7
cgit.js Normal file
View File

@ -0,0 +1,7 @@
/* cgit.js: javacript functions for cgit
*
* Copyright (C) 2006-2018 cgit Development Team <cgit@lists.zx2c4.com>
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/

View File

@ -239,6 +239,11 @@ include::
Name of a configfile to include before the rest of the current config- Name of a configfile to include before the rest of the current config-
file is parsed. Default value: none. See also: "MACRO EXPANSION". file is parsed. Default value: none. See also: "MACRO EXPANSION".
js::
Url which specifies the javascript script document to include in all cgit
pages. Default value: "/cgit.js". Setting this to an empty string will
disable generation of the link to this file in the head section.
local-time:: local-time::
Flag which, if set to "1", makes cgit print commit and tag times in the Flag which, if set to "1", makes cgit print commit and tag times in the
servers timezone. Default value: "0". servers timezone. Default value: "0".

View File

@ -780,6 +780,18 @@ static int emit_css_link(struct string_list_item *s, void *arg)
return 0; return 0;
} }
static int emit_js_link(struct string_list_item *s, void *arg)
{
html("<script type='text/javascript' src='");
if (s)
html_attr(s->string);
else
html_attr((const char *)arg);
html("'></script>\n");
return 0;
}
void cgit_print_docstart(void) void cgit_print_docstart(void)
{ {
char *host = cgit_hosturl(); char *host = cgit_hosturl();
@ -805,6 +817,11 @@ void cgit_print_docstart(void)
else else
emit_css_link(NULL, "/cgit.css"); emit_css_link(NULL, "/cgit.css");
if (ctx.cfg.js.items)
for_each_string_list(&ctx.cfg.js, emit_js_link, NULL);
else
emit_js_link(NULL, "/cgit.js");
if (ctx.cfg.favicon) { if (ctx.cfg.favicon) {
html("<link rel='shortcut icon' href='"); html("<link rel='shortcut icon' href='");
html_attr(ctx.cfg.favicon); html_attr(ctx.cfg.favicon);