[PATCH v6 1/7] config: add js

Christian Hesse list at eworm.de
Fri Jun 29 08:14:04 CEST 2018


Andy Green <andy at warmcat.com> on Fri, 2018/06/29 09:40:
> 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 999db9e..582416e 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 74ace10..52723b3 100644
> --- a/ui-shared.c
> +++ b/ui-shared.c
> @@ -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");

The opening tag still has a slash that should not be there.

> +	}
>  	if (ctx.cfg.favicon) {
>  		html("<link rel='shortcut icon' href='");
>  		html_attr(ctx.cfg.favicon);
> 
> _______________________________________________
> CGit mailing list
> CGit at lists.zx2c4.com
> https://lists.zx2c4.com/mailman/listinfo/cgit



-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)
putchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20180629/a97ba1b7/attachment.asc>


More information about the CGit mailing list