44# ' [pkgdown](https://pkgdown.r-lib.org) makes it easy to turn your package into
55# ' a beautiful website. usethis provides two functions to help you use pkgdown:
66# '
7- # ' * `use_pkgdown()`: creates a pkgdown config file, adds relevant files or
8- # ' directories to `.Rbuildignore` and `.gitignore`, and builds favicons if
9- # ' your package has a logo.
7+ # ' * `use_pkgdown()`: creates a pkgdown config file and adds relevant files or
8+ # ' directories to `.Rbuildignore` and `.gitignore`.
109# '
1110# ' * `use_pkgdown_github_pages()`: implements the GitHub setup needed to
1211# ' automatically publish your pkgdown site to GitHub pages:
@@ -31,28 +30,37 @@ use_pkgdown <- function(config_file = "_pkgdown.yml", destdir = "docs") {
3130 check_is_package(" use_pkgdown()" )
3231 check_installed(" pkgdown" )
3332
34- use_build_ignore(c(config_file , destdir ))
35- use_build_ignore(" pkgdown" )
33+ use_build_ignore(c(config_file , destdir , " pkgdown" ))
3634 use_git_ignore(destdir )
3735
38- ui_todo("
39- Record your site's {ui_field('url')} in the pkgdown config file \\
40- (optional, but recommended)" )
36+ config <- pkgdown_config(destdir )
37+ config_path <- proj_path(config_file )
38+ write_over(config_path , yaml :: as.yaml(config ))
39+ edit_file(config_path )
40+
41+ invisible (TRUE )
42+ }
43+
44+ pkgdown_config <- function (destdir ) {
45+ config <- list (
46+ url = NULL
47+ )
4148
42- if (has_logo() ) {
43- pkgdown_build_favicons(proj_get(), overwrite = TRUE )
49+ if (pkgdown_version() > = " 1.9000 " ) {
50+ config $ template <- list ( bootstrap = 4L )
4451 }
4552
46- config <- proj_path(config_file )
4753 if (! identical(destdir , " docs" )) {
48- write_over( config , paste( " destination: " , destdir ))
54+ config $ destination <- destdir
4955 }
50- edit_file(config )
5156
52- invisible ( TRUE )
57+ config
5358}
5459
55- # tidyverse pkgdown setup ------------------------------------------------------
60+ # wrapping because I need to be able to mock this in tests
61+ pkgdown_version <- function () {
62+ utils :: packageVersion(" pkgdown" )
63+ }
5664
5765# ' @rdname use_pkgdown
5866# ' @export
@@ -75,6 +83,8 @@ use_pkgdown_github_pages <- function() {
7583 }
7684}
7785
86+ # tidyverse pkgdown setup ------------------------------------------------------
87+
7888# ' @details
7989# ' * `use_tidy_pkgdown_github_pages()` is basically
8090# ' [use_pkgdown_github_pages()], so does full pkgdown set up. Note that there
@@ -94,32 +104,22 @@ use_tidy_pkgdown_github_pages <- function() {
94104use_pkgdown_url <- function (url , tr = NULL ) {
95105 tr <- tr %|| % target_repo(github_get = TRUE )
96106
97- config <- pkgdown_config_path()
98- config_lines <- read_utf8(config )
99- url_line <- paste0(" url: " , url )
100- if (! any(grepl(url_line , config_lines ))) {
101- ui_done("
102- Recording {ui_value(url)} as site's {ui_field('url')} in \\
103- {ui_path(config)}" )
104- config_lines <- config_lines [! grepl(" ^url:" , config_lines )]
105- write_utf8(config , c(
106- url_line ,
107- if (length(config_lines ) && nzchar(config_lines [[1 ]])) " " ,
108- config_lines
109- ))
107+ config_path <- pkgdown_config_path()
108+ ui_done("
109+ Recording {ui_value(url)} as site's {ui_field('url')} in \\
110+ {ui_path(config_path)}" )
111+ config <- pkgdown_config_meta()
112+ if (has_name(config , " url" )) {
113+ config $ url <- url
114+ } else {
115+ config <- c(url = url , config )
110116 }
117+ write_utf8(config_path , yaml :: as.yaml(config ))
111118
112- urls <- desc :: desc_get_urls()
113- if (! url %in% urls ) {
114- ui_done(" Adding {ui_value(url)} to {ui_field('URL')} field in DESCRIPTION" )
115- ui_silence(
116- use_description_field(
117- " URL" ,
118- glue_collapse(c(url , urls ), " , " ),
119- overwrite = TRUE
120- )
121- )
122- }
119+ ui_done(" Adding {ui_value(url)} to {ui_field('URL')} field in DESCRIPTION" )
120+ desc <- desc :: desc(file = proj_get())
121+ desc $ add_urls(url )
122+ desc $ write()
123123
124124 gh <- gh_tr(tr )
125125 homepage <- gh(" GET /repos/{owner}/{repo}" )[[" homepage" ]]
@@ -215,16 +215,11 @@ use_pkgdown_travis <- function() {
215215
216216 tr <- target_repo(github_get = TRUE )
217217
218- use_build_ignore(" docs/" )
218+ use_build_ignore(c( " docs/" , " pkgdown " ) )
219219 use_git_ignore(" docs/" )
220220 # TODO: suggest git rm -r --cache docs/
221221 # Can't currently detect if git known files in that directory
222222
223- if (has_logo()) {
224- pkgdown_build_favicons(proj_get(), overwrite = TRUE )
225- use_build_ignore(" pkgdown" )
226- }
227-
228223 ui_todo("
229224 Set up deploy keys by running {ui_code('travis::use_travis_deploy()')}" )
230225 ui_todo(" Insert the following code in {ui_path('.travis.yml')}" )
@@ -242,9 +237,3 @@ use_pkgdown_travis <- function() {
242237
243238 invisible ()
244239}
245-
246- # usethis itself should not depend on pkgdown
247- # all usage of this wrapper is guarded by `check_installed("pkgdown")`
248- pkgdown_build_favicons <- function (... ) {
249- get(" build_favicons" , asNamespace(" pkgdown" ), mode = " function" )(... )
250- }
0 commit comments