feat: add support for customizable QR code text/caption in poster margin
Change-Id: I731628490502fb5af4333ec27105dc61396e6ef8
diff --git a/R/posterdown_html.R b/R/posterdown_html.R
index a321229..87a6e05 100644
--- a/R/posterdown_html.R
+++ b/R/posterdown_html.R
@@ -23,19 +23,39 @@
}
+#' @param url Target URL for the QR code
+#' @param logo Optional path to a logo image to place in the center of the QR code
+#' @param text Optional text/caption to display below the QR code (alias: \code{caption})
+#' @param caption Alias for \code{text}
#' @description Print html code for a linked qr code to the given url
#' @importFrom qrcode add_logo qr_code generate_svg
#' @export
-qrlink <- function(url, logo = NULL) {
+qrlink <- function(url, logo = NULL, text = NULL, caption = text) {
tmp <- tempfile(fileext = ".svg")
qrcode <- qrcode::qr_code(url, ecl = if(is.null(logo)) "L" else "H")
if(!is.null(logo)) {
qrcode <- qrcode::add_logo(qrcode, logo, ecl = "L")
}
qrcode::generate_svg(qrcode, tmp, show = FALSE)
- return(paste0( sprintf('<a class="qrcode" href="%s"><img class="qrcode">', url),
- gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
- '</img></a>'
- ))
+
+ cap_html <- if (!is.null(caption) && nchar(trimws(caption)) > 0) {
+ sprintf('<span class="qrcode-caption">%s</span>', caption)
+ } else {
+ ""
+ }
+
+ if (nchar(cap_html) > 0) {
+ return(paste0( '<div class="qrcode-container"><a class="qrcode" href="', url, '"><img class="qrcode">',
+ gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
+ '</img></a>',
+ cap_html,
+ '</div>'
+ ))
+ } else {
+ return(paste0( sprintf('<a class="qrcode" href="%s"><img class="qrcode">', url),
+ gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
+ '</img></a>'
+ ))
+ }
}
diff --git a/README.md b/README.md
index 87f39a7..c90aa3b 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@
email: kupietz@ids-mannheim.de
website: "http://korap.ids-mannheim.de/instance/icc"
qrlink: >
- `r posterdown.ids::qrlink('https://gitlab.ids-mannheim.de/ids/posterdown')`
+ `r posterdown.ids::qrlink('https://gitlab.ids-mannheim.de/ids/posterdown', text = 'Scan for repository & abstract')`
second_logo:
url: https://raw.githubusercontent.com/brentthorne/posterdown/master/images/betterhexlogo.png
margin-left: 14.5cm
diff --git a/inst/rmarkdown/templates/posterdown_ids/resources/template.html b/inst/rmarkdown/templates/posterdown_ids/resources/template.html
index 967ee77..f0159b7 100644
--- a/inst/rmarkdown/templates/posterdown_ids/resources/template.html
+++ b/inst/rmarkdown/templates/posterdown_ids/resources/template.html
@@ -306,6 +306,27 @@
margin-left: -10px;
}
+#info-column .qrcode-container {
+ margin-bottom: 3.5em;
+}
+
+#info-column .qrcode-container .qrcode,
+#info-column .qrcode-container a.qrcode {
+ margin-bottom: 0.4em;
+ display: block;
+}
+
+#info-column .qrcode-caption {
+ display: block;
+ font-family: "Fira Sans Condensed", "Fira Sans Condensed Light", sans-serif;
+ font-size: 14pt;
+ line-height: 1.25;
+ color: #444444;
+ margin-left: 0;
+ max-width: 7.5cm;
+ word-wrap: break-word;
+}
+
@media print {
#info-column {
/* Physical unit, NOT vh: in headless Chrome vh resolves against the browser
@@ -741,10 +762,27 @@
</div>
<div id="info-column">
$if(contact.qrlink)$
+ $if(contact.qrtext)$
+ <div class="qrcode-container">
+ ${ contact.qrlink }
+ <span class="qrcode-caption">$contact.qrtext$</span>
+ </div>
+ <br/>
+ $elseif(contact.qrcaption)$
+ <div class="qrcode-container">
+ ${ contact.qrlink }
+ <span class="qrcode-caption">$contact.qrcaption$</span>
+ </div>
+ <br/>
+ $else$
${ contact.qrlink }
<br/>
+ $endif$
$elseif(contact.qrcode)$
+ <div class="qrcode-container">
<img class="qrcode" src="$contact.qrcode$"/>
+ $if(contact.qrtext)$<span class="qrcode-caption">$contact.qrtext$</span>$elseif(contact.qrcaption)$<span class="qrcode-caption">$contact.qrcaption$</span>$endif$
+ </div>
<br/>
$endif$
<b>$if(lang.de)$Kontakt$else$Contact$endif$:</b><br/>
diff --git a/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd
index 8349dae..0252171 100644
--- a/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd
+++ b/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd
@@ -19,7 +19,7 @@
email: kupietz@ids-mannheim.de
website: "https://www.ids-mannheim.de/digspra/"
qrlink: >
- `r posterdown.ids::qrlink('https://korap.ids-mannheim.de/gerrit/plugins/gitiles/IDS-Mannheim/posterdown')`
+ `r posterdown.ids::qrlink('https://korap.ids-mannheim.de/gerrit/plugins/gitiles/IDS-Mannheim/posterdown', text = 'Scan for repository & source')`
column_numbers: 2
# logoright_name: https://raw.githubusercontent.com/brentthorne/posterdown/master/images/betterhexlogo.png
second_logo: