[PATCH v4 1/6] config: add js
Andy Green
andy at warmcat.com
Mon Jun 25 07:49:46 CEST 2018
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 at warmcat.com>
Reviewed-by: John Keeping <john at keeping.me.uk>
---
Makefile | 1 +
cgit.c | 3 +++
cgit.h | 1 +
cgit.js | 0
cgitrc.5.txt | 5 +++++
ui-shared.c | 5 +++++
6 files changed, 15 insertions(+)
create mode 100644 cgit.js
diff --git a/Makefile b/Makefile
index 137150c..de7e13e 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 bdb2fad..8b23c8f 100644
--- a/cgit.c
+++ b/cgit.c
@@ -146,6 +146,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.root_readme = xstrdup(value);
else if (!strcmp(name, "css"))
ctx.cfg.css = xstrdup(value);
+ else if (!strcmp(name, "js"))
+ ctx.cfg.js = xstrdup(value);
else if (!strcmp(name, "favicon"))
ctx.cfg.favicon = xstrdup(value);
else if (!strcmp(name, "footer"))
@@ -384,6 +386,7 @@ static void prepare_context(void)
ctx.cfg.branch_sort = 0;
ctx.cfg.commit_sort = 0;
ctx.cfg.css = "/cgit.css";
+ ctx.cfg.js = "/cgit.js";
ctx.cfg.logo = "/cgit.png";
ctx.cfg.favicon = "/favicon.ico";
ctx.cfg.local_time = 0;
diff --git a/cgit.h b/cgit.h
index 99ea7a2..e5a703e 100644
--- a/cgit.h
+++ b/cgit.h
@@ -194,6 +194,7 @@ struct cgit_config {
char *clone_prefix;
char *clone_url;
char *css;
+ char *js;
char *favicon;
char *footer;
char *head_include;
diff --git a/cgit.js b/cgit.js
new file mode 100644
index 0000000..e69de29
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 99fc799..2737008 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -248,6 +248,11 @@ inline-readme::
individually also choose to ignore this global list, and create a
repo-specific list by using 'repo.inline-readme'.
+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 082a6f1..e2f3d55 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -787,6 +787,11 @@ void cgit_print_docstart(void)
html("<link rel='stylesheet' type='text/css' href='");
html_attr(ctx.cfg.css);
html("'/>\n");
+ if (*ctx.cfg.js) {
+ html("<script type='text/javascript' src='");
+ html_attr(ctx.cfg.js);
+ html("'/></script>\n");
+ }
if (ctx.cfg.favicon) {
html("<link rel='shortcut icon' href='");
html_attr(ctx.cfg.favicon);
More information about the CGit
mailing list