df <- purrr::pluck(params, "headlines")
showImages <- "thumbnail" %in% colnames(df)
fn_block <- fs::path_package(package = "headliner", 
                             "rmd", "templates", "card_tex.Rmd")

if (showImages) {
  df <- dplyr::mutate(df,
                      tmp = sprintf("%s/%04d.jpg",
                                    here::here("tmp"),
                                    dplyr::row_number()))
  dir.create(here::here("tmp"))
  purrr::walk2(dplyr::pull(df, thumbnail),
               dplyr::pull(df, tmp),
               download.file)
}

# ---- write and knit data.frame
md <- purrr::pmap_chr(df, knitr::knit_expand, fn_block, delim = c("$(", ")"))
# default
fn_block <- fs::path_package(package = "headliner",
                             "rmd", "templates", "item.Rmd")
md <- character(1L)

if (purrr::pluck(params, "block_type") == "card") {
  # inject card css
  md <- c(md,
          "<style>.row.display-flex{display:flex;flex-wrap:wrap}.thumbnail{height:95%}.thumbnail{display:flex;flex-direction:column}</style>", 
          "")
  fn_block <- fs::path_package(package = "headliner",
                               "rmd", "templates", "card_html.Rmd")
}

md <- c(md, purrr::pmap_chr(df, knitr::knit_expand, fn_block))

title: r purrr::pluck(params, "main_title")

knitr::knit(text = md, quiet = TRUE) %>% 
  glue::glue_collapse("\n")
glue::glue("{ fn_block }")
# print(head(df))
print(md)


zambujo/headliner documentation built on Nov. 12, 2020, 6:35 p.m.