Skip to content

Commit

Permalink
Merge pull request #1 from mitchelloharawild/master
Browse files Browse the repository at this point in the history
keeping up to date with vitae
  • Loading branch information
dendroica authored May 17, 2024
2 parents bcb45bb + 274fa85 commit d349ca7
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 159 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: vitae
Title: Curriculum Vitae for R Markdown
Version: 0.5.3.9000
Version: 0.5.4
Authors@R: c(
person("Mitchell", "O'Hara-Wild", role=c("aut", "cre"), email = "[email protected]", comment=c(ORCID = "0000-0001-6729-7695")),
person("Rob", "Hyndman", email="[email protected]", role=c("aut"), comment = c(ORCID = "0000-0002-2140-5352")),
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# vitae (development version)
# vitae 0.5.4

* Fixed `bibliography_entries()` failing to render PDF outputs with recent
versions of pandoc (#246).

# vitae 0.5.3

Expand Down
12 changes: 6 additions & 6 deletions R/bibliography.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ knit_print.vitae_bibliography <- function(x, options = knitr::opts_current$get()
startlabel <- x %@% "startlabel"
endlabel <- x %@% "endlabel"

# Convert file separator to format expected by citeproc
file <- gsub("\\", "/", file, fixed = TRUE)

out <- glue(
'
::: {#bibliography}
<< file >>
::: {#refs-<< rlang::hash_file(file) >>}
:::
',
.open = "<<", .close = ">>"
)
knitr::asis_output(out, meta = list(structure(x$id, class = "vitae_nocite")))

# Convert file separator to format expected by pandoc-citeproc on Windows
file <- gsub("\\", "/", file, fixed = TRUE)

knitr::asis_output(out, meta = list(structure(list(file = file, id = x$id), class = "vitae_nocite")))
}
23 changes: 9 additions & 14 deletions R/cv_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,8 @@ cv_document <- function(..., pandoc_args = NULL, pandoc_vars = NULL,
pandoc_args <- c(pandoc_args, rmarkdown::pandoc_variable_arg(names(pandoc_vars)[[i]], pandoc_vars[[i]]))
}

# Inject multiple-bibliographies lua filter
mult_bib <- file.path(tempdir(), "multiple-bibliographies.lua")
if(rmarkdown::pandoc_version() <= package_version("2.7.3")) {
warn(sprintf("Detected pandoc version %s, which may cause issues with bibliography_entries().
Please update pandoc if you have any issues knitting bibliographies (this can be done by updating RStudio).", rmarkdown::pandoc_version()))
}
cat(
gsub("<<PANDOC_PATH>>", rmarkdown::find_pandoc()$dir, fixed = TRUE,
readLines(system.file("multiple-bibliographies.lua", package = "vitae", mustWork = TRUE), encoding = "UTF-8")),
file = mult_bib, sep = "\n"
)

pandoc_args <- c(
c(rbind("--lua-filter", mult_bib)),
c(rbind("--lua-filter", system.file("multiple-bibliographies.lua", package = "vitae", mustWork = TRUE))),
pandoc_args
)

Expand All @@ -41,8 +29,15 @@ Please update pandoc if you have any issues knitting bibliographies (this can be
files_dir, output_dir)

# Add citations to front matter yaml, there may be a better way to do this.
# For example, @* wildcard. Keeping as is to avoid unintended side effects.
meta_nocite <- vapply(knit_meta, inherits, logical(1L), "vitae_nocite")
metadata$nocite <- c(metadata$nocite, paste0("@", do.call(c, knit_meta[meta_nocite]), collapse = ", "))

bib_files <- lapply(knit_meta[meta_nocite], function(x) x$file)
names(bib_files) <- vapply(bib_files, rlang::hash_file, character(1L))
metadata$bibliography <- bib_files

bib_ids <- unique(unlist(lapply(knit_meta[meta_nocite], function(x) x$id)))
metadata$nocite <- c(metadata$nocite, paste0("@", bib_ids, collapse = ", "))
if(is.null(metadata$csl)) metadata$csl <- system.file("vitae.csl", package = "vitae", mustWork = TRUE)

body <- partition_yaml_front_matter(xfun::read_utf8(input_file))$body
Expand Down
3 changes: 2 additions & 1 deletion R/preview.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Include a preview of the CV template output for documentation
#'
#' @param input Path to the CV's template rmd file
#' @param template Name of the template
#'
#' @keywords internal
insert_preview <- function(template) {
preview <- paste0("preview-", template, ".png")
Expand Down
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# vitae <img src="man/figures/logo.png" align="right" />

Expand All @@ -8,12 +7,12 @@
<!-- badges: start -->

[![CRAN
status](https://www.r-pkg.org/badges/version/vitae)](https://cran.r-project.org/package=vitae)
status](https://www.r-pkg.org/badges/version/vitae.png)](https://cran.r-project.org/package=vitae)
[![R check
status](https://github.com/mitchelloharawild/vitae/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mitchelloharawild/vitae/actions/workflows/R-CMD-check.yaml)
[![Lifecycle:
maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#maturing)
[![Downloads](https://cranlogs.r-pkg.org/badges/vitae)](https://cran.r-project.org/package=vitae)
[![Downloads](https://cranlogs.r-pkg.org/badges/vitae.png)](https://cran.r-project.org/package=vitae)
<!-- badges: end -->

## Templates and tools for making a Résumé/CV
Expand Down Expand Up @@ -57,10 +56,13 @@ If you prefer a guided introduction in video form, check out [Bryan
Jenks](https://github.com/tallguyjenks)
[freeCodeCamp](https://github.com/freeCodeCamp/freeCodeCamp) [tech
talk](https://youtu.be/cMlRAiQUdD8):

[![](man/figures/freecodecamp.jpg)](https://youtu.be/cMlRAiQUdD8)

Creating a new CV with `vitae` can be done using the RStudio R Markdown
template selector: ![](man/figures/template_gui.png)
template selector:

![](man/figures/template_gui.png)

These templates leverage the strength of rmarkdown to include common
information in the YAML header (name, position, social links…) and
Expand All @@ -76,17 +78,17 @@ programmatically into your CV.

There are currently 6 templates available in this package:

| [**vitae::awesomecv**](https://pkg.mitchelloharawild.com/vitae/reference/awesomecv.html) | [**vitae::hyndman**](https://pkg.mitchelloharawild.com/vitae/reference/hyndman.html) |
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| [<img src="man/figures/preview-awesomecv.png" width="415" alt="Preview of awesomecv" />](https://pkg.mitchelloharawild.com/vitae/reference/awesomecv.html) | [<img src="man/figures/preview-hyndman.png" width="415" alt="Preview of hyndman" />](https://pkg.mitchelloharawild.com/vitae/reference/hyndman.html) |
| [**vitae::awesomecv**](https://pkg.mitchelloharawild.com/vitae/reference/awesomecv.html) | [**vitae::hyndman**](https://pkg.mitchelloharawild.com/vitae/reference/hyndman.html) |
|-------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| [<img src="man/figures/preview-awesomecv.png" width="415" alt="awesomecv" />](https://pkg.mitchelloharawild.com/vitae/reference/awesomecv.html) | [<img src="man/figures/preview-hyndman.png" width="415" alt="hyndman" />](https://pkg.mitchelloharawild.com/vitae/reference/hyndman.html) |

| [**vitae::latexcv**](https://pkg.mitchelloharawild.com/vitae/reference/latexcv.html) | [**vitae::markdowncv**](https://pkg.mitchelloharawild.com/vitae/reference/markdowncv.html) |
|----------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [<img src="man/figures/preview-latexcv.png" width="415" alt="Preview of latexcv" />](https://pkg.mitchelloharawild.com/vitae/reference/latexcv.html) | [<img src="man/figures/preview-markdowncv.png" width="415" alt="Preview of markdowncv" />](https://pkg.mitchelloharawild.com/vitae/reference/markdowncv.html) |
| [**vitae::latexcv**](https://pkg.mitchelloharawild.com/vitae/reference/latexcv.html) | [**vitae::markdowncv**](https://pkg.mitchelloharawild.com/vitae/reference/markdowncv.html) |
|-------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [<img src="man/figures/preview-latexcv.png" width="415" alt="latexcv" />](https://pkg.mitchelloharawild.com/vitae/reference/latexcv.html) | [<img src="man/figures/preview-markdowncv.png" width="415" alt="markdowncv" />](https://pkg.mitchelloharawild.com/vitae/reference/markdowncv.html) |

| [**vitae::moderncv**](https://pkg.mitchelloharawild.com/vitae/reference/moderncv.html) | [**vitae::twentyseconds**](https://pkg.mitchelloharawild.com/vitae/reference/twentyseconds.html) |
|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| [<img src="man/figures/preview-moderncv.png" width="415" alt="Preview of moderncv" />](https://pkg.mitchelloharawild.com/vitae/reference/moderncv.html) | [<img src="man/figures/preview-twentyseconds.png" width="415" alt="Preview of twentyseconds" />](https://pkg.mitchelloharawild.com/vitae/reference/twentyseconds.html) |
| [**vitae::moderncv**](https://pkg.mitchelloharawild.com/vitae/reference/moderncv.html) | [**vitae::twentyseconds**](https://pkg.mitchelloharawild.com/vitae/reference/twentyseconds.html) |
|----------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [<img src="man/figures/preview-moderncv.png" width="415" alt="moderncv" />](https://pkg.mitchelloharawild.com/vitae/reference/moderncv.html) | [<img src="man/figures/preview-twentyseconds.png" width="415" alt="twentyseconds" />](https://pkg.mitchelloharawild.com/vitae/reference/twentyseconds.html) |

Extending the package to add new templates is a somewhat simple process
(details in the [creating vitae
Expand All @@ -112,6 +114,11 @@ vignette).
- [Adam Kirosingh](https://github.com/akirosingh/CV)
- [Marco Lombardi](https://github.com/mlombardi6/awesome-template)
- [Anthony Romero](https://github.com/ganthonyr/CV)
- [André Calero Valdez](https://github.com/sumidu/acv) This version uses
a database to manage the content and automatically updates the content
once a week using Github actions. PDF is then added as a release after
rendering. Also uses a forked version of the package to remove the
trailing dot in brief entries.

Add your vitae to the list using a PR.

Expand Down
18 changes: 6 additions & 12 deletions README.Rmd → README.qmd
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
---
output: github_document
format: gfm
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

# vitae <img src="man/figures/logo.png" align="right" />
*/ˈviːteɪ/*

Expand Down Expand Up @@ -58,9 +49,11 @@ tinytex::install_tinytex()
The *vitae* package currently supports `r length(list.dirs("inst/rmarkdown/templates/", recursive = FALSE))` popular CV templates. You can see some previews of the available templates [below](#templates).

If you prefer a guided introduction in video form, check out [Bryan Jenks](https://github.com/tallguyjenks)' [freeCodeCamp](https://github.com/freeCodeCamp/freeCodeCamp) [tech talk](https://youtu.be/cMlRAiQUdD8):

[![](man/figures/freecodecamp.jpg)](https://youtu.be/cMlRAiQUdD8)

Creating a new CV with `vitae` can be done using the RStudio R Markdown template selector:

![](man/figures/template_gui.png)

These templates leverage the strength of rmarkdown to include common information in the YAML header (name, position, social links...) and extended information in the main body. The main body of the CV is written using markdown, and allows for data-driven generation of entries using the [`*_entries` functions](https://pkg.mitchelloharawild.com/vitae/reference/cv_entries.html). This allows you to import your working history from other sources (such as ORCID, Google Scholar, or a maintained dataset), and include them programmatically into your CV.
Expand All @@ -72,7 +65,7 @@ There are currently `r length(template_name)` templates available in this packag
```{r show-previews, echo = FALSE, results = "asis"}
preview_url <- sprintf("https://pkg.mitchelloharawild.com/vitae/reference/%s.html", template_name)
preview_title <- sprintf("[**vitae::%s**](%s)", template_name, preview_url)
preview_image <- sprintf("[![Preview of %s](%s){width=415px}](%s)", template_name, template_preview, preview_url)
preview_image <- sprintf("[<img src=\"%s\" width=\"415\" alt=\"%s\" />](%s)", template_preview, template_name, preview_url)
preview_row <- (seq_along(preview_title)+1)%/%2
tables <- lapply(split(seq_along(preview_title), preview_row), function(i){
Expand All @@ -84,7 +77,7 @@ tables <- lapply(split(seq_along(preview_title), preview_row), function(i){
""
)
})
cat(do.call(c, tables), sep = "\n")
cat(c("```{=markdown}", unlist(tables), "```"), sep = "\n")
```
Extending the package to add new templates is a somewhat simple process (details in the [creating vitae templates](https://pkg.mitchelloharawild.com/vitae/articles/extending.html) vignette).

Expand All @@ -104,6 +97,7 @@ Extending the package to add new templates is a somewhat simple process (details
- [Adam Kirosingh](https://github.com/akirosingh/CV)
- [Marco Lombardi](https://github.com/mlombardi6/awesome-template)
- [Anthony Romero](https://github.com/ganthonyr/CV)
- [André Calero Valdez](https://github.com/sumidu/acv) This version uses a database to manage the content and automatically updates the content once a week using Github actions. PDF is then added as a release after rendering. Also uses a forked version of the package to remove the trailing dot in brief entries.

Add your vitae to the list using a PR.

Expand Down
104 changes: 56 additions & 48 deletions inst/multiple-bibliographies.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
--[[
multiple-bibliographies – create multiple bibliographies
multibib – create multiple bibliographies
Copyright © 2018-2020 Albert Krewinkel
Modified 19/10/2020 by Mitchell O'Hara-Wild
Copyright © 2018-2022 Albert Krewinkel
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand All @@ -16,69 +15,63 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]
PANDOC_VERSION:must_be_at_least '2.11'

local List = require 'pandoc.List'
local utils = require 'pandoc.utils'
local stringify = utils.stringify
local run_json_filter = utils.run_json_filter

--- get the type of meta object
local metatype = pandoc.utils.type or
function (v)
local metatag = type(v) == 'table' and v.t and v.t:gsub('^Meta', '')
return metatag and metatag ~= 'Map' and metatag or type(v)
end

--- Collection of all cites in the document
local all_cites = {}
--- Document meta value
local doc_meta = pandoc.Meta{}

--- Div used by pandoc-citeproc to insert the bibliography.
--- Div used by citeproc to insert the bibliography.
local refs_div = pandoc.Div({}, pandoc.Attr('refs'))

local supports_quiet_flag = (function ()
-- We use pandoc instead of pandoc-citeproc starting with pandoc 2.11
if PANDOC_VERSION >= "2.11" then
return true
end
local version = pandoc.pipe('<<PANDOC_PATH>>/pandoc-citeproc', {'--version'}, '')
local major, minor, patch = version:match 'pandoc%-citeproc (%d+)%.(%d+)%.?(%d*)'
major, minor, patch = tonumber(major), tonumber(minor), tonumber(patch)
return major > 0
or minor > 14
or (minor == 14 and patch >= 5)
end)()
-- Div filled by citeproc with properties set according to
-- the output format and the attributes of cs:bibliography
local refs_div_with_properties

local function run_citeproc(doc, quiet)
if PANDOC_VERSION >= "2.11" then
return run_json_filter(
doc,
'<<PANDOC_PATH>>/pandoc',
{'--from=json', '--to=json', '--citeproc', quiet and '--quiet' or nil}
)
else
-- doc = run_json_filter(doc, '<<PANDOC_PATH>>/pandoc-citeproc')
return run_json_filter(
doc,
'<<PANDOC_PATH>>/pandoc-citeproc',
{FORMAT, (quiet and supports_quiet_flag) and '-q' or nil}
)
--- Run citeproc on a pandoc document
local citeproc
if utils.citeproc then
-- Built-in Lua function
citeproc = utils.citeproc
else
-- Use pandoc as a citeproc processor
citeproc = function (doc)
local opts = {'--from=json', '--to=json', '--citeproc', '--quiet'}
return run_json_filter(doc, 'pandoc', opts)
end
end


--- Resolve citations in the document by combining all bibliographies
-- before running pandoc-citeproc on the full document.
local function resolve_doc_citations (doc)
-- combine all bibliographies
local meta = doc.meta
local orig_bib = meta.bibliography
meta.bibliography = pandoc.MetaList{orig_bib}
for name, value in pairs(meta) do
if name:match('^bibliography_') then
table.insert(meta.bibliography, value)
local bibconf = meta.bibliography
meta.bibliography = pandoc.MetaList{}
if metatype(bibconf) == 'table' then
for _, value in pairs(bibconf) do
table.insert(meta.bibliography, stringify(value))
end
end
-- add dummy div to catch the created bibliography
-- add refs div to catch the created bibliography
table.insert(doc.blocks, refs_div)
-- resolve all citations
-- doc = run_json_filter(doc, '<<PANDOC_PATH>>/pandoc-citeproc')
doc = run_citeproc(doc)
-- remove catch-all bibliography
table.remove(doc.blocks)
doc = citeproc(doc)
-- remove catch-all bibliography and keep it for future use
refs_div_with_properties = table.remove(doc.blocks)
-- restore bibliography to original value
doc.meta.bibliography = orig_bib
return doc
Expand All @@ -103,22 +96,37 @@ local function meta_for_pandoc_citeproc (bibliography)
return new_meta
end

local function remove_duplicates(classes)
local seen = {}
return classes:filter(function(x)
if seen[x] then
return false
else
seen[x] = true
return true
end
end)
end

--- Create a bibliography for a given topic. This acts on all divs whose
-- ID matches "bibliography", and uses the path contained within the div
-- ID starts with "refs", followed by nothing but underscores and
-- alphanumeric characters.
local function create_topic_bibliography (div)

local is_bib = div.identifier == 'bibliography'
if not is_bib then
local name = div.identifier:match('^refs[-_]?([-_%w]*)$')
local bibfile = name and (doc_meta.bibliography or {})[name]
if not bibfile then
return nil
end
local bibfile = div.content[1].content[1].text
local tmp_blocks = {pandoc.Para(all_cites), refs_div}
local tmp_meta = meta_for_pandoc_citeproc(bibfile)
local tmp_doc = pandoc.Pandoc(tmp_blocks, tmp_meta)
local res = run_citeproc(tmp_doc, true) -- try to be quiet
local res = citeproc(tmp_doc)
-- First block of the result contains the dummy paragraph, second is
-- the refs Div filled by pandoc-citeproc.
-- the refs Div filled by citeproc.
div.content = res.blocks[2].content
-- Set the classes and attributes as citeproc did it on refs_div
div.classes = remove_duplicates(refs_div_with_properties.classes)
div.attributes = refs_div_with_properties.attributes
return div
end

Expand Down
Loading

0 comments on commit d349ca7

Please sign in to comment.