Skip to content

Commit

Permalink
Merge pull request #247 from carpentries/no-more-infinite-loops
Browse files Browse the repository at this point in the history
avoid infinite loops with serve()
  • Loading branch information
zkamvar authored Feb 10, 2022
2 parents 229e78b + f68db74 commit 452e381
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Package: sandpaper
Title: Create and Curate Carpentries Lessons
Version: 0.1.3
Version: 0.1.4
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
role = c("aut", "cre"),
email = "zkamvar@gmail.com",
email = "zkamvar@carpentries.org",
comment = c(ORCID = "0000-0003-1458-7108")),
person(given = "François",
family = "Michonneau",
role = c("ctb"),
email = "fmichonneau@carpentries.org"),
email = "francois@carpentries.org"),
person())
Description: We provide tools to build a Carpentries-themed lesson repository
into an accessible standalone static website. These include local tools and
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# sandpaper 0.1.4

BUG FIX
-------

* `sandpaper::build_lesson()` no longer creates an infinite loop when called
after `sandpaper::serve()` (@zkamvar, #247)

# sandpaper 0.1.3

MISC
Expand Down
20 changes: 19 additions & 1 deletion R/serve.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,32 @@
#' sandpaper::serve()
#' }
#nocov start
# Note: we can not test this in covr because I'm not entirely sure of how to get
# it going
serve <- function(path = ".") {
path <- root_path(path)
rend <- function(file_list = ".") {
for (f in file_list) {
build_lesson(f, preview = FALSE)
}
}
# path to the production folder that {servr} needs to render
prod <- fs::path(path_site(path), "docs")
# filter function generator for {servr} to exclude the site folder
#
# This assumes that the input to the function will be whole file names
# which is the output of list.files() with recurse = TRUE and
# full.names = TRUE
#
# @param base the base path
make_filter <- function(base = path) {
no_site <- file.path(base, "site")
no_git <- file.path(base, ".git")
# return a filter function for the files
function(x) x[!startsWith(x, no_site) | !startsWith(x, no_git)]
}
# to start, build the site and then watch things:
rend()
servr::httw(fs::path(path_site(path), "docs"), watch = path, handler = rend)
servr::httw(prod, watch = path, filter = make_filter(path), handler = rend)
}
#nocov end

0 comments on commit 452e381

Please sign in to comment.