https://github.com/cran/pkgdown
Revision 651be9df176377fc2008a1e0990db54e7e2f0daf authored by Hadley Wickham on 14 September 2019, 23:10:08 UTC, committed by cran-robot on 14 September 2019, 23:10:08 UTC
1 parent 6522ead
Raw File
Tip revision: 651be9df176377fc2008a1e0990db54e7e2f0daf authored by Hadley Wickham on 14 September 2019, 23:10:08 UTC
version 1.4.1
Tip revision: 651be9d
build-home-citation.R

has_citation <- function(path = ".") {
  file_exists(path(path, 'inst/CITATION'))
}

create_meta <- function(path) {
  path <- path(path, "DESCRIPTION")

  dcf <- read.dcf(path)
  meta <- as.list(dcf[1, ])

  if (!is.null(meta$Encoding)) {
    meta <- lapply(meta, iconv, from = meta$Encoding, to = "UTF-8")
  }

  meta
}

read_citation <- function(path = ".") {
  if (!has_citation(path)) {
    return(character())
  }
  meta <- create_meta(path)
  cit_path <- path(path, 'inst/CITATION')

  utils::readCitationFile(cit_path, meta = meta)
}

data_home_sidebar_citation <- function(pkg = ".") {
  pkg <- as_pkgdown(pkg)

  if (!has_citation(pkg$src_path)) {
    return(character())
  }

  citation <- paste0("<a href='authors.html'>Citing ", pkg$package, "</li>")

  sidebar_section("Citation", citation)
}

data_citations <- function(pkg = ".") {
  pkg <- as_pkgdown(pkg)
  cit <- read_citation(pkg$src_path)

  list(
    html = format(cit, style = "html"),
    bibtex = format(cit, style = "bibtex")
  ) %>% purrr::transpose()
}

build_citation_authors <- function(pkg = ".") {
  pkg <- as_pkgdown(pkg)

  source <- github_source_links(pkg$github_url, "inst/CITATION")

  data <- list(
    pagetitle = "Citation and Authors",
    citations = data_citations(pkg),
    authors = unname(data_authors(pkg)$all),
    source = source
  )

  render_page(pkg, "citation-authors", data, "authors.html")
}
back to top