[PATCH v2 15/15] render: adapt for providing extra filter args for plain
John Keeping
john at keeping.me.uk
Mon Jun 18 21:25:29 CEST 2018
On Mon, Jun 18, 2018 at 10:58:31AM +0800, Andy Green wrote:
> This changes the render filter exec part to provide a second
> and third argument, which are used by md2html to fix up the url
> path for "plain" for the repo, eg, "/cgit/plain/" and
> "?h=mybranch", as required by the modifications to md2html in
> the previous patches.
>
> The combination means cgit becomes able to serve assets using
> markdown urls starting from the repo root dir, without mentioning
> any virtual url part specific to a cgit or other web rendering
> instance, while respecting the version context.
>
> Eg, continuing the example of the arguments being
> "/cgit/plain/" and "?h=mybranch" from above, if the markdown has
>
> ![overview](./doc-assets/overview.png)
>
> the img src will be fixed up to
>
> "/cgit/plain/doc-assets/overview.png?h=mybranch"
>
> If the same document is viewed from a different rev in cgit, the
> processed markdown url will change to match the cgit context, even
> though the markdown relative URL is the same for all versions.
>
> Signed-off-by: Andy Green <andy at warmcat.com>
> ---
> filter.c | 5 ++++-
> ui-tree.c | 13 +++++++++++--
> 2 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/filter.c b/filter.c
> index 4ae4aaa..7c1f188 100644
> --- a/filter.c
> +++ b/filter.c
> @@ -424,6 +424,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
> argument_count = 12;
> break;
>
> + case RENDER:
> + argument_count = 3;
> + break;
> +
> case EMAIL:
> argument_count = 2;
> break;
> @@ -434,7 +438,6 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
>
> case SOURCE:
> case ABOUT:
> - case RENDER:
> argument_count = 1;
> break;
>
> diff --git a/ui-tree.c b/ui-tree.c
> index 9f59d18..5bbe30d 100644
> --- a/ui-tree.c
> +++ b/ui-tree.c
> @@ -102,16 +102,25 @@ static void print_buffer(const char *basename, char *buf, unsigned long size)
> }
>
> static void render_buffer(struct cgit_filter *render, const char *name,
> - char *buf, unsigned long size)
> + char *buf, unsigned long size)
> {
> char *filter_arg = xstrdup(name);
> + char *repo_url = cgit_repourl(ctx.repo->url);
> + struct strbuf sb_plain = STRBUF_INIT, sb_postfix = STRBUF_INIT;
> +
> + strbuf_addf(&sb_plain, "%splain/", repo_url);
This doesn't always work (if we don't have cfg.virtual_root set it's
wrong).
The logic in ui-shared.c::reporevlink() does the right thing, and it
might be possible to extract a helper function but we may just have to
replicate it since that version generates the URL as an HTML attribute
value.
> + if (ctx.qry.head)
> + strbuf_addf(&sb_postfix, "?h=%s", ctx.qry.head);
> + free(repo_url);
>
> html("<div class='blob'>");
> - cgit_open_filter(render, filter_arg);
> + cgit_open_filter(render, filter_arg, sb_plain.buf, sb_postfix.buf);
> html_raw(buf, size);
> cgit_close_filter(render);
> html("</div>");
>
> + strbuf_release(&sb_plain);
> + strbuf_release(&sb_postfix);
> free(filter_arg);
> }
>
More information about the CGit
mailing list