From 58a831d3fc9ab9c7c15bef972e1f6947c752276d Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 9 Oct 2020 12:30:47 -0400 Subject: [PATCH] Preserve query string in rendered zet links --- zet.dpi.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/zet.dpi.c b/zet.dpi.c index b292f05..79d23ca 100644 --- a/zet.dpi.c +++ b/zet.dpi.c @@ -73,6 +73,11 @@ struct zet_mtime { int mtime; }; +struct zet_renderopt { + struct html_renderopt html; + const char *query; +}; + enum page { PAGE_NEW, PAGE_ALL, @@ -618,9 +623,9 @@ static void parse_req_uri(char *path, char **hashp, char **queryp) { static int md_rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque) { - struct html_renderopt *options = opaque; + struct zet_renderopt *options = opaque; - if (link != NULL && (options->flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size)) + if (link != NULL && (options->html.flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size)) return 0; BUFPUTSL(ob, "data, "ยง", sigil_size)) { houdini_escape_href(ob, link->data + sigil_size, link->size - sigil_size); + const char *query = options->query; + if (query != NULL) { + bufputc(ob, '?'); + bufputs(ob, query); + } } else houdini_escape_href(ob, link->data, link->size); } @@ -645,9 +655,9 @@ md_rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, co houdini_escape_html0(ob, title->data, title->size, 0); } - if (options->link_attributes) { + if (options->html.link_attributes) { bufputc(ob, '\"'); - options->link_attributes(ob, link, opaque); + options->html.link_attributes(ob, link, opaque); bufputc(ob, '>'); } else { BUFPUTSL(ob, "\">"); @@ -661,7 +671,7 @@ md_rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, co static int md_rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque) { - struct html_renderopt *options = opaque; + struct zet_renderopt *options = opaque; if (!link || !link->size) return 0; BUFPUTSL(ob, "size) return 0; - if ((options->flags & HTML_SAFELINK) != 0 && + if ((options->html.flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size) && type != MKDA_EMAIL) return 0; @@ -743,9 +753,9 @@ md_rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, } } - if (options->link_attributes) { + if (options->html.link_attributes) { bufputc(ob, '\"'); - options->link_attributes(ob, link, opaque); + options->html.link_attributes(ob, link, opaque); bufputc(ob, '>'); } else { BUFPUTSL(ob, "\">"); @@ -844,10 +854,11 @@ static int dpi_serve_zet(int fd, char *path) { } struct sd_callbacks callbacks; - struct html_renderopt options; + struct zet_renderopt options; struct sd_markdown *markdown; struct buf *ob = bufnew(128); - sdhtml_renderer(&callbacks, &options, HTML_ESCAPE); + sdhtml_renderer(&callbacks, &options.html, HTML_ESCAPE); + options.query = query; callbacks.link = md_rndr_link; callbacks.image = md_rndr_image; callbacks.autolink = md_rndr_autolink; @@ -894,7 +905,8 @@ static int dpi_serve_zet(int fd, char *path) { result_title[sizeof(result_title)-1] = '\0'; return 0; } - rc = dprintf(fd, "
  • ", result_id); + rc = dprintf(fd, "
  • ", result_id, + query ? "?" : "", query ? query : ""); rc |= write_html(fd, result_title, strlen(result_title)); rc |= write_buf(fd, "
  • "); } while (1);