Skip to content

Commit

Permalink
Don't build Github issue and pull request templates (r-lib#2362)
Browse files Browse the repository at this point in the history
Fixes r-lib#2358

Co-authored-by: Hadley Wickham <[email protected]>
  • Loading branch information
2 people authored and SebKrantz committed Jun 1, 2024
1 parent dcc9cdf commit 99c711d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 19 additions & 6 deletions R/build-home-md.R
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/test-build-home-md.R
Original file line number Diff line number Diff line change
@@ -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())
})



0 comments on commit 99c711d

Please sign in to comment.