Add linked qrcode: qrlink
Change-Id: I344ae90b5cc6aad9f61ff5ac9e42fe8680af7164
diff --git a/DESCRIPTION b/DESCRIPTION
index 6aec2a2..497fc0d 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -23,6 +23,7 @@
BugReports: https://github.com/brentthorne/posterdown/issues
Imports:
pagedown,
+ qrcode,
rmarkdown,
yaml
Suggests: knitr
diff --git a/NAMESPACE b/NAMESPACE
index 2d0979e..daf7202 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -4,3 +4,7 @@
export(posterdown_betterport)
export(posterdown_html)
export(posterdown_ids)
+export(qrlink)
+importFrom(qrcode,add_logo)
+importFrom(qrcode,generate_svg)
+importFrom(qrcode,qr_code)
diff --git a/R/posterdown_html.R b/R/posterdown_html.R
index e391b92..8ac3ea5 100644
--- a/R/posterdown_html.R
+++ b/R/posterdown_html.R
@@ -62,3 +62,20 @@
css = NULL) {
pagedown::poster_relaxed(..., css = css, template = template)
}
+
+#' @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) {
+ 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, 1e5)),
+ '</img></a>'
+ ))
+}
+
diff --git a/README.md b/README.md
index c9741ec..65584a3 100644
--- a/README.md
+++ b/README.md
@@ -58,6 +58,8 @@
email: kupietz@ids-mannheim.de
website: "http://korap.ids-mannheim.de/instance/icc"
qrcode: "my_qrcode.svg"
+ qrlink: >
+ `r posterdown::qrlink('https://korap.ids-mannheim.de/gerrit/plugins/gitiles/IDS-Mannheim/posterdown')`
```
For a complete example, see [skeleton.Rmd](./inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd)
diff --git a/inst/rmarkdown/templates/posterdown_ids/resources/template.html b/inst/rmarkdown/templates/posterdown_ids/resources/template.html
index d6aec3d..5b929e1 100644
--- a/inst/rmarkdown/templates/posterdown_ids/resources/template.html
+++ b/inst/rmarkdown/templates/posterdown_ids/resources/template.html
@@ -671,7 +671,10 @@
</div>
<div id="info-column">
- $if(contact.qrcode)$
+ $if(contact.qrlink)$
+ ${ contact.qrlink }
+ <br/>
+ $elseif(contact.qrcode)$
<img class="qrcode" src="$contact.qrcode$"/>
<br/>
$endif$
diff --git a/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd
index 316b8e8..ef72d11 100644
--- a/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd
+++ b/inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd
@@ -18,7 +18,8 @@
department: Digital Linguistics
email: kupietz@ids-mannheim.de
website: "https://www.ids-mannheim.de/digspra/"
- qrcode: "gerrit_qrcode.svg"
+ qrlink: >
+ `r posterdown::qrlink('https://korap.ids-mannheim.de/gerrit/plugins/gitiles/IDS-Mannheim/posterdown')`
column_numbers: 2
# logoright_name: https://raw.githubusercontent.com/brentthorne/posterdown/master/images/betterhexlogo.png
logoleft_name: https://raw.githubusercontent.com/brentthorne/posterdown/master/images/betterhexlogo.png
@@ -34,7 +35,6 @@
```{r setup, include=FALSE}
library(qrcode)
knitr::opts_chunk$set(dev = 'svg', echo = FALSE)
-generate_svg(qr_code("https://korap.ids-mannheim.de/gerrit/plugins/gitiles/IDS-Mannheim/posterdown"), "gerrit_qrcode.svg")
```
# Introduction