From 671640e4d767bff7a461b75a263c9ada4a27f825 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 26 Sep 2022 15:36:55 -0700 Subject: [PATCH 1/6] parse the titles for the sidebar --- R/utils-sidebar.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils-sidebar.R b/R/utils-sidebar.R index 499ef7154..ea5a6b110 100644 --- a/R/utils-sidebar.R +++ b/R/utils-sidebar.R @@ -122,7 +122,7 @@ create_sidebar <- function(chapters, name = "", html = "", - i - 1, ". ", info$pagetitle, + i - 1, ". ", parse_title(info$pagetitle), "") res[i] <- create_sidebar_item(html, page_link, position) } From cc2e7f70ce6f67108a4fe3d1cb9baca6fa3933cc Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 26 Sep 2022 15:37:24 -0700 Subject: [PATCH 2/6] replace index title if missing --- R/utils-varnish.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/R/utils-varnish.R b/R/utils-varnish.R index b9d67d7c6..67b0be6cf 100644 --- a/R/utils-varnish.R +++ b/R/utils-varnish.R @@ -65,9 +65,18 @@ set_globals <- function(path) { idx <- these_resources[["."]] idx <- idx[as_html(idx) == "index.html"] instructor_sidebar <- create_sidebar(c(idx, these_resources[["episodes"]])) + # check if we have a title in the index sidebar and replace with + # "summary and schedule" if it does not exist. + idx_item <- xml2::read_html(instructor_sidebar[[1]]) + idx_link <- xml2::xml_find_first(idx_item, ".//a") + idx_text <- xml2::xml_contents(idx_link) + if (length(idx_text) == 1 && xml2::xml_text(idx_text) == "0. ") { + xml2::xml_set_text(idx_link, "Summary and Schedule") + } else { + xml2::xml_set_text(idx_text, sub("^0[.] ", "", xml2::xml_text(idx_text))) + } + sindex <- create_sidebar_item(nodes = NULL, as.character(idx_link), 1) learner_sidebar <- instructor_sidebar - sindex <- create_sidebar_item(nodes = NULL, - "Summary and Schedule", 1) instructor_sidebar[[1]] <- sindex learner_sidebar[[1]] <- sub("Schedule", "Setup", sindex) From fa261826275f1e8a434e59357b9c0a350af97478 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 26 Sep 2022 15:37:53 -0700 Subject: [PATCH 3/6] replace index header if missing --- R/build_home.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/build_home.R b/R/build_home.R index 4503f96ee..c8fdd254a 100644 --- a/R/build_home.R +++ b/R/build_home.R @@ -23,14 +23,18 @@ build_home <- function(pkg, quiet, sidebar = NULL, new_setup = TRUE, next_page = nav <- get_nav_data(idx_file, fs::path_file(idx_file), page_forward = next_page) - nav$pagetitle <- "Summary and Schedule" + if (nav$pagetitle == "") { + nav$pagetitle <- "Summary and Schedule" + } nav$page_forward <- as_html(nav$page_forward, instructor = TRUE) page_globals$instructor$update(nav) page_globals$instructor$set("syllabus", paste(syl, collapse = "")) page_globals$instructor$set("readme", use_instructor(html)) page_globals$instructor$set("setup", use_instructor(setup)) - nav$pagetitle <- "Summary and Setup" + if (nav$pagetitle == "") { + nav$pagetitle <- "Summary and Setup" + } nav$page_forward <- as_html(nav$page_forward) page_globals$learner$update(nav) page_globals$learner$set("readme", use_learner(html)) From 31d6b9d141f5ee1d621bcffe6965f45ab750c33b Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 26 Sep 2022 15:39:33 -0700 Subject: [PATCH 4/6] update tests --- tests/testthat/_snaps/build_html.md | 4 ++-- tests/testthat/test-build_html.R | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/build_html.md b/tests/testthat/_snaps/build_html.md index a091771bf..4de7da2f1 100644 --- a/tests/testthat/_snaps/build_html.md +++ b/tests/testthat/_snaps/build_html.md @@ -36,7 +36,7 @@ writeLines(sidelinks_instructor) Output Learner View - Summary and Schedule + TEST title 1. introduction Key Points Instructor Notes @@ -49,7 +49,7 @@ writeLines(sidelinks_learner) Output Instructor View - Summary and Setup + TEST title 1. introduction Key Points Glossary diff --git a/tests/testthat/test-build_html.R b/tests/testthat/test-build_html.R index f12d81d1c..924ada094 100644 --- a/tests/testthat/test-build_html.R +++ b/tests/testthat/test-build_html.R @@ -1,5 +1,8 @@ res <- restore_fixture() withr::defer(clear_globals()) +idx <- readLines(fs::path(res, "index.md")) +writeLines(c(idx[1], "title: '**TEST** title'", idx[-1]), + fs::path(res, "index.md")) set_globals(res) pkg <- pkgdown::as_pkgdown(path_site(res)) # shim for downlit ---------------------------------------------------------- @@ -32,9 +35,18 @@ test_that("[build_home()] works independently", { expect_true(fs::file_exists(learn_index)) idx <- xml2::read_html(learn_index) expect_true(xml2::xml_find_lgl(idx, "boolean(.//main/section[@id='setup'])")) + newtitle <- xml2::xml_find_first(idx, ".//span[@class='current-chapter']/*") + expect_identical(as.character(newtitle), "TEST") + newtitle <- xml2::xml_find_first(idx, ".//h1/*") + expect_identical(as.character(newtitle), "TEST") + instruct_index <- fs::path(pkg$dst_path, "instructor", "index.html") expect_true(fs::file_exists(instruct_index)) idx <- xml2::read_html(instruct_index) + newtitle <- xml2::xml_find_first(idx, ".//span[@class='current-chapter']/*") + expect_identical(as.character(newtitle), "TEST") + newtitle <- xml2::xml_find_first(idx, ".//h1/*") + expect_identical(as.character(newtitle), "TEST") expect_true(xml2::xml_find_lgl(idx, "boolean(.//main/section[@id='setup'])")) expect_true(xml2::xml_find_lgl(idx, "boolean(.//main/section[@id='schedule'])")) }) From 1d9164c3da3ba7ae21261e8c5fde6c2d9accc865 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 26 Sep 2022 15:44:34 -0700 Subject: [PATCH 5/6] bump version; add news --- DESCRIPTION | 2 +- NEWS.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 21b367112..104a32e30 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sandpaper Title: Create and Curate Carpentries Lessons -Version: 0.10.0 +Version: 0.10.1 Authors@R: c( person(given = "Zhian N.", family = "Kamvar", diff --git a/NEWS.md b/NEWS.md index 10a3362f9..d21bca15a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,17 @@ +# sandpaper 0.10.1 + +NEW FEATURES +------------ + +* If the `index.md (or Rmd)` file has a `title` YAML element, this will take + precedence over the default title of "Summary and Setup". + (requested: @SaraMorsey, #339; fixed: @zkamvar #342) + +BUG FIX +------- + +* Titles in navigation bar now have Markdown parsed correctly. + # sandpaper 0.10.0 NEW FEATURES From c1c134adf6bafbb35c2b58033876f8dbd0727e6f Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Mon, 26 Sep 2022 15:48:40 -0700 Subject: [PATCH 6/6] GADSBY --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index d21bca15a..d39c6ec3f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,7 @@ NEW FEATURES * If the `index.md (or Rmd)` file has a `title` YAML element, this will take precedence over the default title of "Summary and Setup". - (requested: @SaraMorsey, #339; fixed: @zkamvar #342) + (requested: @SaraMorsy, #339; fixed: @zkamvar #342) BUG FIX -------