aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2018-06-23 18:25:53 +0800
committerChristian Hesse <mail@eworm.de>2019-06-04 13:35:43 +0200
commitf38a59a4ffdfc53b2b78d6b8c6a02979f7d04e90 (patch)
treec714615a7c591feb651f47e5b72d62f5c0f61a96
parentcss: change to be a list (diff)
downloadcgit-f38a59a4ffdfc53b2b78d6b8c6a02979f7d04e90.tar.xz
cgit-f38a59a4ffdfc53b2b78d6b8c6a02979f7d04e90.zip
config: add js
Just like the config allows setting css URL path, add a config for setting the js URL path Setting the js path to an empty string disables emitting the reference to it in the head section. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk> Signed-off-by: Christian Hesse <mail@eworm.de>
-rw-r--r--Makefile1
-rw-r--r--cgit.c2
-rw-r--r--cgit.h1
-rw-r--r--cgit.js7
-rw-r--r--cgitrc.5.txt5
-rw-r--r--ui-shared.c11
6 files changed, 27 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index e690c7f..068b132 100644
--- a/Makefile
+++ b/Makefile
@@ -87,6 +87,7 @@ install: all
$(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
$(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
$(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 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico
$(INSTALL) -m 0644 robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt
diff --git a/cgit.c b/cgit.c
index 36f847d..f9fb12a 100644
--- a/cgit.c
+++ b/cgit.c
@@ -131,6 +131,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.root_readme = xstrdup(value);
else if (!strcmp(name, "css"))
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"))
ctx.cfg.favicon = xstrdup(value);
else if (!strcmp(name, "footer"))
diff --git a/cgit.h b/cgit.h
index 8cf09ed..bb5e1f5 100644
--- a/cgit.h
+++ b/cgit.h
@@ -263,6 +263,7 @@ struct cgit_config {
int branch_sort;
int commit_sort;
struct string_list mimetypes;
+ struct string_list js;
struct cgit_filter *about_filter;
struct cgit_filter *commit_filter;
struct cgit_filter *source_filter;
diff --git a/cgit.js b/cgit.js
new file mode 100644
index 0000000..b9e8f4c
--- /dev/null
+++ b/cgit.js
@@ -0,0 +1,7 @@
+/* cgit.css: 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)
+ */
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 2a77dda..e1e783a 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -239,6 +239,11 @@ include::
Name of a configfile to include before the rest of the current config-
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::
Flag which, if set to "1", makes cgit print commit and tag times in the
servers timezone. Default value: "0".
diff --git a/ui-shared.c b/ui-shared.c
index 8b378c9..3513e10 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -779,6 +779,15 @@ static int emit_css_link(struct string_list_item *s, void *arg)
return 0;
}
+static int emit_js_link(struct string_list_item *s, void *arg)
+{
+ html("<script type='text/javascript' src='");
+ html_attr(s->string);
+ html("'></script>\n");
+
+ return 0;
+}
+
void cgit_print_docstart(void)
{
char *host = cgit_hosturl();
@@ -804,6 +813,8 @@ void cgit_print_docstart(void)
else
emit_css_link(NULL, "/cgit.css");
+ for_each_string_list(&ctx.cfg.js, emit_js_link, NULL);
+
if (ctx.cfg.favicon) {
html("<link rel='shortcut icon' href='");
html_attr(ctx.cfg.favicon);