Skip to content

Latest commit

 

History

History
118 lines (107 loc) · 5.41 KB

_make_pdf.qmd

File metadata and controls

118 lines (107 loc) · 5.41 KB
title subtitle date author citation_url format editor
Openscapes Champions Lesson Series
Open educational resources for Openscapes Champions
today
Openscapes team
pdf
toc toc-depth number-sections number-depth output-file output-ext
true
3
true
1
openscapes-series
pdf
source
```{r} #| echo: false #| eval: true # This approach borrowed from https://github.com/royal-statistical-society/datavisguide/blob/main/_make_pdf.qmd process_qmd <- function(file, fpath_in = "images/", fpath_out = "images/", level = 1) { doc <- readLines(file) end_yaml <- which(doc == "---")[2] out_doc <- doc[seq(end_yaml + 1, length(doc))] # remove margin illustration in pathways margin_start <- which(out_doc == "::: column-margin") if (length(margin_start == 1)) { out_doc <- c( out_doc[seq(1, margin_start - 1)], out_doc[seq(margin_start + 4, length(out_doc))] ) } if (fpath_in != fpath_out) { out_doc <- stringr::str_replace_all(out_doc, fpath_in, fpath_out) } # increase the level by n = level - 1 by adding a # to each heading out_doc <- gsub("^(#+)", paste0("\\1", paste0(rep("#", level), collapse = "")), out_doc) res <- knitr::knit_child(text = out_doc, quiet = TRUE, options = list(eval = FALSE, echo = TRUE)) return(res) } ``` ```{r} #| output: asis #| echo: false #| eval: true #| message: false # To add a new page, add a new list item to the "parts" list, following the # attern here, listing the page title, the directory, the file name, # and the level at which it should appear in the nav/chapter hierarchy. # Standalone headings can be added as a single character preceded by the # '#' (e.g., '# Additional Lessons') parts <- list( list(title = "Welcome", dir = ".", file = "index.qmd", img_path = "images/", level = 1), list(title = "Program Summary", dir = ".", file = "program-summary.qmd", img_path = "images/", level = 1), list(title = "What to Expect", dir = ".", file = "what-to-expect.qmd", img_path = "images/", level = 1), list(title = "Pathways & Outcomes", dir = ".", file = "pathways.qmd", img_path = "images/", level = 1), list(title = "Core Lessons", dir = "core-lessons", file = "index.qmd", img_path = "images/", level = 1), list(title = "Mindset", dir = "core-lessons", file = "mindset.qmd", img_path = "images/", level = 2), list(title = "Better Science", dir = "core-lessons", file = "better-science.qmd", img_path = "images/", level = 2), list(title = "Team Culture", dir = "core-lessons", file = "team-culture.qmd", img_path = "images/", level = 2), list(title = "Data Strategies", dir = "core-lessons", file = "data-strategies.qmd", img_path = "images/", level = 2), list(title = "Coding Strategies", dir = "core-lessons", file = "coding-strategies.qmd", img_path = "images/", level = 2), list(title = "Open Communities", dir = "core-lessons", file = "communities.qmd", img_path = "images/", level = 2), list(title = "GitHub Strategies", dir = "core-lessons/github", file = "index.qmd", img_path = "images/", level = 2), list(title = "GitHub for publishing", dir = "core-lessons/github/", file = "github-pub.qmd", img_path = "images/", level = 3), list(title = "GitHub for project management", dir = "core-lessons/github/", file = "github-issues.qmd", img_path = "images/", level = 3), "# Additional Lessons", list(title = "Code of Conduct", dir = "additional-lessons", file = "code-of-conduct.qmd", img_path = "images/", level = 2), list(title = "Reporting & SciComm", dir = "additional-lessons", file = "reporting-scicomm.qmd", img_path = "images/", level = 2), list(title = "Documentation", dir = "additional-lessons", file = "documentation.qmd", img_path = "images/", level = 2), list(title = "Forked Lessons", dir = "forked-lessons", file = "index.qmd", img_path = "images/", level = 1), list(title = "How Do I...", dir = "how-do-i", file = "index.qmd", img_path = "images/", level = 1), list(title = "Setup RStudio & GitHub", dir = "how-do-i", file = "setup-rstudio-github.qmd", img_path = "images/", level = 2), list(title = "Do & fix git things", dir = "how-do-i", file = "do-fix-git-things.qmd", img_path = "images/", level = 2), list(title = "Refactor code", dir = "how-do-i", file = "refactor-modularize-code.qmd", img_path = "images/", level = 2), list(title = "Start with Quarto", dir = "how-do-i", file = "create-publish-quarto.qmd", img_path = "images/", level = 2), list(title = "Ask questions", dir = "how-do-i", file = "ask-questions.qmd", img_path = "images/", level = 2), list(title = "Discuss community", dir = "how-do-i", file = "discuss-community.qmd", img_path = "images/", level = 2), list(title = "Reuse Openscapes Approach", dir = "how-do-i", file = "reuse-openscapes-approach.qmd", img_path = "images/", level = 2), "# Inspiration", list(title = "Resources that influence us", dir = "inspiration", file = "resources-that-influence.qmd", img_path = "images/", level = 2) ) purrr::walk( parts, function(x) { if (is.character(x)) { cat("\n\n") cat(x) cat("\n\n") return(NULL) } doc_txt <- process_qmd( file = file.path(x$dir, x$file), fpath_in = x$img_path, fpath_out = file.path(x$dir, x$img_path), level = x$level ) title <- paste(paste0(rep("#", x$level), collapse = ""), x$title) cat(title) cat("\n") cat("\n") cat(unlist(doc_txt), sep = "\n") cat("\n") cat("\n") } ) ```