]> granicus.if.org Git - cgit/commitdiff
config: add js
authorAndy Green <andy@warmcat.com>
Sat, 23 Jun 2018 10:25:53 +0000 (18:25 +0800)
committerAndy Green <andy@warmcat.com>
Thu, 28 Jun 2018 23:53:21 +0000 (07:53 +0800)
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>
Makefile
cgit.c
cgit.h
cgit.js [new file with mode: 0644]
cgitrc.5.txt
ui-shared.c

index 137150c956c7faa27835e2fab40debd2c3fd5b0e..de7e13ef7a955b4b1832d854997557867ab63eec 100644 (file)
--- 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 bdb2fadee562f337dcfb565c17b742ada08cda1a..8b23c8ffb838496827ba363333c815b4f70e4e04 100644 (file)
--- 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 999db9e386db59b944065ce0feb5539e3948a551..582416eb7f3dfc6a45247c3db7efd6c262dbb141 100644 (file)
--- 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 (file)
index 0000000..e69de29
index 99fc7992a1943bccf00bef3511fbbff7c489d870..27370087d2e0764eb9971d361ead744fa0e1f2be 100644 (file)
@@ -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".
index 74ace108786834f7cebd1b9f97c7a846152ade6c..e1ff349f8818d2c48953891e77cb0b13bad23b44 100644 (file)
@@ -798,6 +798,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);