diff --git a/make_screenshots.R b/make_screenshots.R new file mode 100644 index 00000000..1555e486 --- /dev/null +++ b/make_screenshots.R @@ -0,0 +1,87 @@ +#!/usr/bin/env Rscript +# Written by Candace Savonen Jan 2022 + +if (!('devtools' %in% installed.packages())) { + # install.packages("remotes", repos = "http://cran.us.r-project.org") +} + +if (!('optparse' %in% installed.packages())) { + # install.packages("optparse", repos = "http://cran.us.r-project.org") +} + +# Find .git root directory +root_dir <- rprojroot::find_root(rprojroot::has_dir(".git")) + + +Sys.setenv("CHROMOTE_CHROME" = "/usr/bin/vivaldi") + +library(optparse) +library(magrittr) + +option_list <- list( + optparse::make_option( + c("--repo"), + type = "character", + default = NULL, + help = "GitHub repository name, e.g. jhudsl/OTTR_Template", + ), + optparse::make_option( + c("--git_pat"), + type = "character", + default = NULL, + help = "GitHub personal access token", + ), + optparse::make_option( + c("--output_dir"), + type = "character", + default = "resources/chapt_screen_images", + help = "Output directory where the chapter's screen images should be stored", + ), + optparse::make_option( + c("--base_url"), + type = "character", + default = NULL, + help = "Output directory where the chapter's screen images should be stored", + ) +) + +# Read the arguments passed +opt_parser <- optparse::OptionParser(option_list = option_list) +opt <- optparse::parse_args(opt_parser) + +output_folder <- file.path(opt$output_dir) +if (!dir.exists(output_folder)) { + dir.create(output_folder, recursive = TRUE) +} + +if (is.null(opt$base_url)) { + base_url <- cow::get_pages_url(repo_name = opt$repo, git_pat = opt$git_pat) + base_url <- gsub("/$", "", base_url) +} + +# Collect all the chapter pages for the url given +chapt_df <- ottrpal::get_chapters(html_page = file.path(root_dir, "docs", "index.html"), + base_url = base_url) + +# Now take screenshots for each +file_names <- lapply(chapt_df$url, function(url) { + file_name <- gsub(".html", ".png", file.path(output_folder, basename(url))) + + # Get rid of special characters because leanpub no like + file_name <- gsub(":|?|!|\\'", "", file_name) + + # Take the screenshot + webshot2::webshot(url, file = file_name) + + return(file_name) + +}) + +# Save file of chapter urls and file_names +chapt_df <- chapt_df %>% + dplyr::mutate(img_path = unlist(file_names)) + +chapt_df %>% + readr::write_tsv(file.path(output_folder, "chapter_urls.tsv")) + +message(paste("Image Chapter key written to: ", file.path(output_folder, "chapter_urls.tsv"))) diff --git a/manuscript/1-Introduction.md b/manuscript/1-Introduction.md deleted file mode 100644 index e97d74ee..00000000 --- a/manuscript/1-Introduction.md +++ /dev/null @@ -1,7 +0,0 @@ -# 1 Introduction - -{type: iframe, title:1 Introduction, width:800, height:600, poster:resources/chapt_screen_images/introduction.png} -![](https://jhudatascience.org/OTTR_Template/no_toc/introduction.html) - - - diff --git a/manuscript/2-A-new-chapter.md b/manuscript/2-A-new-chapter.md deleted file mode 100644 index 7b11214b..00000000 --- a/manuscript/2-A-new-chapter.md +++ /dev/null @@ -1,7 +0,0 @@ -# 2 A new chapter - -{type: iframe, title:2 A new chapter, width:800, height:600, poster:resources/chapt_screen_images/a-new-chapter.png} -![](https://jhudatascience.org/OTTR_Template/no_toc/a-new-chapter.html) - - - diff --git a/manuscript/3-References.md b/manuscript/3-References.md deleted file mode 100644 index b66fda3a..00000000 --- a/manuscript/3-References.md +++ /dev/null @@ -1,7 +0,0 @@ -# 3 References - -{type: iframe, title:3 References, width:800, height:600, poster:resources/chapt_screen_images/references.png} -![](https://jhudatascience.org/OTTR_Template/no_toc/references.html) - - - diff --git a/manuscript/About-the-Authors.md b/manuscript/About-the-Authors.md deleted file mode 100644 index 56f3d5d3..00000000 --- a/manuscript/About-the-Authors.md +++ /dev/null @@ -1,7 +0,0 @@ -# About the Authors - -{type: iframe, title:About the Authors, width:800, height:600, poster:resources/chapt_screen_images/about-the-authors.png} -![](https://jhudatascience.org/OTTR_Template/no_toc/about-the-authors.html) - - - diff --git a/manuscript/About-this-Course.md b/manuscript/About-this-Course.md deleted file mode 100644 index c9e920b8..00000000 --- a/manuscript/About-this-Course.md +++ /dev/null @@ -1,7 +0,0 @@ -# About this Course - -{type: iframe, title:About this Course, width:800, height:600, poster:resources/chapt_screen_images/index.png} -![](https://jhudatascience.org/OTTR_Template/no_toc/index.html) - - - diff --git a/manuscript/Book.txt b/manuscript/Book.txt deleted file mode 100644 index 6576cbb6..00000000 --- a/manuscript/Book.txt +++ /dev/null @@ -1,5 +0,0 @@ -1-Introduction.md -2-A-new-chapter.md -3-References.md -About-this-Course.md -About-the-Authors.md diff --git a/manuscript/resources/chapt_screen_images/a-new-chapter.png b/manuscript/resources/chapt_screen_images/a-new-chapter.png deleted file mode 100644 index 3b1da09a..00000000 Binary files a/manuscript/resources/chapt_screen_images/a-new-chapter.png and /dev/null differ diff --git a/manuscript/resources/chapt_screen_images/about-the-authors.png b/manuscript/resources/chapt_screen_images/about-the-authors.png deleted file mode 100644 index bd50cb76..00000000 Binary files a/manuscript/resources/chapt_screen_images/about-the-authors.png and /dev/null differ diff --git a/manuscript/resources/chapt_screen_images/index.png b/manuscript/resources/chapt_screen_images/index.png deleted file mode 100644 index 800870a6..00000000 Binary files a/manuscript/resources/chapt_screen_images/index.png and /dev/null differ diff --git a/manuscript/resources/chapt_screen_images/introduction.png b/manuscript/resources/chapt_screen_images/introduction.png deleted file mode 100644 index b2233aec..00000000 Binary files a/manuscript/resources/chapt_screen_images/introduction.png and /dev/null differ diff --git a/manuscript/resources/chapt_screen_images/references.png b/manuscript/resources/chapt_screen_images/references.png deleted file mode 100644 index d31b8e5b..00000000 Binary files a/manuscript/resources/chapt_screen_images/references.png and /dev/null differ diff --git a/resources/chapt_screen_images/a-new-chapter.png b/resources/chapt_screen_images/a-new-chapter.png index 3b1da09a..5d00734b 100644 Binary files a/resources/chapt_screen_images/a-new-chapter.png and b/resources/chapt_screen_images/a-new-chapter.png differ diff --git a/resources/chapt_screen_images/about-the-authors.png b/resources/chapt_screen_images/about-the-authors.png index bd50cb76..0a063018 100644 Binary files a/resources/chapt_screen_images/about-the-authors.png and b/resources/chapt_screen_images/about-the-authors.png differ diff --git a/resources/chapt_screen_images/chapter_urls.tsv b/resources/chapt_screen_images/chapter_urls.tsv index 9c3a0a00..66773b66 100644 --- a/resources/chapt_screen_images/chapter_urls.tsv +++ b/resources/chapt_screen_images/chapter_urls.tsv @@ -1,6 +1,6 @@ url chapt_title img_path -https://jhudatascience.org/OTTR_Template/no_toc/index.html About this Course resources/chapt_screen_images/index.png -https://jhudatascience.org/OTTR_Template/no_toc/introduction.html 1 Introduction resources/chapt_screen_images/introduction.png -https://jhudatascience.org/OTTR_Template/no_toc/a-new-chapter.html 2 A new chapter resources/chapt_screen_images/a-new-chapter.png -https://jhudatascience.org/OTTR_Template/no_toc/about-the-authors.html About the Authors resources/chapt_screen_images/about-the-authors.png -https://jhudatascience.org/OTTR_Template/no_toc/references.html 3 References resources/chapt_screen_images/references.png +https://jhudatascience.org/OTTR_Template/index.html About this Course resources/chapt_screen_images/index.png +https://jhudatascience.org/OTTR_Template/introduction.html 1 Introduction resources/chapt_screen_images/introduction.png +https://jhudatascience.org/OTTR_Template/a-new-chapter.html 2 A new chapter resources/chapt_screen_images/a-new-chapter.png +https://jhudatascience.org/OTTR_Template/about-the-authors.html About the Authors resources/chapt_screen_images/about-the-authors.png +https://jhudatascience.org/OTTR_Template/references.html 3 References resources/chapt_screen_images/references.png diff --git a/resources/chapt_screen_images/index.png b/resources/chapt_screen_images/index.png index 800870a6..d6416b01 100644 Binary files a/resources/chapt_screen_images/index.png and b/resources/chapt_screen_images/index.png differ diff --git a/resources/chapt_screen_images/introduction.png b/resources/chapt_screen_images/introduction.png index b2233aec..56d9bf1b 100644 Binary files a/resources/chapt_screen_images/introduction.png and b/resources/chapt_screen_images/introduction.png differ diff --git a/resources/chapt_screen_images/references.png b/resources/chapt_screen_images/references.png index d31b8e5b..2a191fc2 100644 Binary files a/resources/chapt_screen_images/references.png and b/resources/chapt_screen_images/references.png differ