# format authors (based on `citation()`)
author <- .read_authors_at_R_field(meta$`Authors@R`)
author <- format(author, include = c("given", "family"))
# formatted description fields
descr <- list(
  author = paste(paste(head(author, -1L), collapse = ", "),
                 tail(author, 1L), sep = " and "),
  year = sub("-.*", "", meta$Date),
  title = paste0(meta$Package, ": ", meta$Title),
  note = sprintf("R package version %s", meta$Version),
  url = meta$URL
)

# Package citation

bibentry(
  bibtype = "Misc",
  textVersion = paste0(
    descr$author,
    " (", descr$year, "). ",
    descr$title, ". ",
    descr$note, ". ",
    descr$url
  ),
  header = gettextf("To cite package %s in publications, use:",
                    sQuote("ggalluvial")),
  key = "ggalluvial-package",
  title = descr$title,
  author = descr$author,
  year = descr$year,
  note = descr$note,
  url = descr$url
)

# JOSS article citation

bibentry(
  bibtype = "Article",
  header = gettextf("To cite layered alluvial plots as implemented in %s:",
                    sQuote("ggalluvial")),
  key = "ggalluvial-article",
  title = "{ggalluvial}: Layered Grammar for Alluvial Plots",
  author = "Jason Cory Brunson",
  year = "2020",
  journal = "Journal of Open Source Software",
  volume = "5",
  number = "49",
  pages = "2017",
  doi = "10.21105/joss.02017"
)
