From e74f3197dbe5eb2e0607a8a2dfe6e8b16501b423 Mon Sep 17 00:00:00 2001 From: Henrik Sloot <16246049+hsloot@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:12:55 +0200 Subject: [PATCH] Don't build Github issue and pull request templates (#2362) Fixes #2358 Co-authored-by: Hadley Wickham --- NEWS.md | 2 ++ R/build-home-md.R | 25 +++++++++++++++++++------ tests/testthat/test-build-home-md.R | 28 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 tests/testthat/test-build-home-md.R diff --git a/NEWS.md b/NEWS.md index 1799866cc..4fd82eb4b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # pkgdown (development version) +* `build_home()` no longer renders Github issue and pull request templates (@hsloot, #2362) + # pkgdown 2.0.8 * pkgdown is now compatible with (and requires) bslib >= 0.5.1 diff --git a/R/build-home-md.R b/R/build-home-md.R index f2309deae..54024a5f6 100644 --- a/R/build-home-md.R +++ b/R/build-home-md.R @@ -1,24 +1,37 @@ build_home_md <- function(pkg) { + mds <- package_mds(pkg$src_path, in_dev = pkg$development$in_dev) - mds <- dir_ls(pkg$src_path, glob = "*.md") + lapply(mds, render_md, pkg = pkg) + invisible() +} + +package_mds <- function(path, in_dev = FALSE) { + mds <- dir_ls(path, glob = "*.md") # Also looks in .github, if it exists - github_path <- path(pkg$src_path, ".github") + github_path <- path(path, ".github") if (dir_exists(github_path)) { mds <- c(mds, dir_ls(github_path, glob = "*.md")) } # Remove files handled elsewhere - handled <- c("README.md", "LICENSE.md", "LICENCE.md", "NEWS.md", "cran-comments.md") + handled <- c("README.md", "LICENSE.md", "LICENCE.md", "NEWS.md") mds <- mds[!path_file(mds) %in% handled] # Do not build 404 page if in-dev - if (pkg$development$in_dev) { + if (in_dev) { mds <- mds[fs::path_file(mds) != "404.md"] } - lapply(mds, render_md, pkg = pkg) - invisible() + # Remove files that don't need to be rendered + no_render <- c( + "issue_template.md", + "pull_request_template.md", + "cran-comments.md" + ) + mds <- mds[!fs::path_file(mds) %in% no_render] + + unname(mds) } render_md <- function(pkg, filename) { diff --git a/tests/testthat/test-build-home-md.R b/tests/testthat/test-build-home-md.R new file mode 100644 index 000000000..dc3270249 --- /dev/null +++ b/tests/testthat/test-build-home-md.R @@ -0,0 +1,28 @@ +test_that("can find files in root and .github", { + dir <- withr::local_tempdir() + dir_create(path(dir, ".github")) + file_create(path(dir, "a.md")) + file_create(path(dir, ".github", "b.md")) + + mds <- withr::with_dir(dir, package_mds(".")) + expect_equal(mds, c("a.md", "./.github/b.md")) +}) + +test_that("drops files handled elsewhere", { + dir <- withr::local_tempdir() + dir_create(path(dir, ".github")) + file_create(path(dir, c("README.md", "LICENSE.md", "NEWS.md"))) + + expect_equal(withr::with_dir(dir, package_mds(".")), character()) +}) + +test_that("drops files that don't need to be rendered", { + dir <- withr::local_tempdir() + dir_create(path(dir, ".github")) + file_create(path(dir, c("cran-comments.md", "issue_template.md"))) + + expect_equal(withr::with_dir(dir, package_mds(".")), character()) +}) + + +