-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathbuild-home-md.R
More file actions
101 lines (83 loc) · 2.61 KB
/
Copy pathbuild-home-md.R
File metadata and controls
101 lines (83 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
build_home_md <- function(pkg) {
mds <- package_mds(pkg$src_path, in_dev = pkg$development$in_dev)
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(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")
# Append user-defined ignores from .pkgdownignore
user_ignores <- read_pkgdownignore(path)
if (length(user_ignores) > 0) {
cli::cli_inform("Ignoring: {user_ignores}")
}
handled <- c(handled, user_ignores)
# handled <- c(handled)
mds <- mds[!path_file(mds) %in% handled]
# Do not build 404 page if in-dev
if (in_dev) {
mds <- mds[path_file(mds) != "404.md"]
}
# Remove files that don't need to be rendered
no_render <- c(
"issue_template.md",
"pull_request_template.md",
"cran-comments.md"
)
mds <- mds[!path_file(mds) %in% no_render]
unname(mds)
}
render_md <- function(pkg, filename) {
cli::cli_inform("Reading {src_path(path_rel(filename, pkg$src_path))}")
body <- markdown_body(pkg, filename, strip_header = TRUE)
path <- path_ext_set(path_file(filename), "html")
render_page(
pkg,
"title-body",
data = list(
pagetitle = attr(body, "title"),
body = body,
filename = filename,
source = repo_source(pkg, path_rel(filename, pkg$src_path))
),
path = path
)
if (path == "404.html") {
update_html(path(pkg$dst_path, path), tweak_link_absolute, pkg = pkg)
}
check_missing_images(pkg, filename, path)
invisible()
}
#' Read .pkgdownignore file
#'
#' Searches for .pkgdownignore in standard pkgdown config locations.
#' Returns filenames to exclude (one per line, with comments ignored).
#'
#' @param path Path to the package root
#' @return Character vector of filenames to exclude
#' @noRd
read_pkgdownignore <- function(path) {
# Check standard pkgdown config locations:
candidates <- c(
path(path, ".pkgdownignore"),
path(path, "_pkgdown", ".pkgdownignore"),
path(path, "pkgdown", ".pkgdownignore")
)
# Read output from all ignore files
ignore_paths <- candidates[file_exists(candidates)]
if (length(ignore_paths) == 0) {
return(character())
}
# Combine lines from all ignore files
lines <- unlist(lapply(ignore_paths, readLines))
# Remove comments & empty lines and trim whitespace
lines <- lines[!grepl("^\\s*#", lines)]
lines <- lines[nzchar(trimws(lines))]
unique(trimws(lines))
}