Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 27 additions & 29 deletions R/publish.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,41 @@
#'
#' Publish a book to a Connect Server. By default, you should render the book
#' locally before publishing.
#'
#' @inheritParams rsconnect::deploySite
#'
#' @param name Name of the book (this will be used in the URL path of the
#' published book). Defaults to the \code{book_filename} in
#' \code{_bookdown.yml} if not specified.
#' @param account Account name to publish to. Will default to any previously
#' published to account or any single account already associated with
#' \code{server}.
#' @param server Server to publish to (by default connect.posit.cloud, but any
#' Posit Connect server can be published to).
#' @param ... Other arguments to be passed to [rsconnect::deploySite()].
#' @note Previously the default server was bookdown.org, which will be sunset.
#' You are no longer recommended to publish to bookdown.org.
#' @param server Server to publish to (by default connect.posit.cloud, but
#' any Posit Connect server can be published to).
#'
#' @export
publish_book = function(name = NULL, account = NULL, server = "connect.posit.cloud", ...) {
# delete local records of bookdown.org
accounts = rsconnect::accounts()
x1 = 'bookdown.org' %in% accounts$server
x2 = 'bookdown.org' %in% rsconnect::servers()$name
if (x1 || x2) {
warning(
'bookdown.org will be sunset on January 31, 2026. Please consider ',
'publishing to https://connect.posit.cloud instead.'
)
if (readline('Do you want to remove the bookdown.org server now? Your book will _not_ be removed. (y/n) ') == 'y') {
if (x1) rsconnect::removeAccount(server = 'bookdown.org')
if (x2) rsconnect::removeServer('bookdown.org')
}
if (readline('Do you want to delete local records of the Connect deployment? Your book will _not_ be deleted (y/n) ') == 'y') {
rsconnect::forgetDeployment()
}
}
# if there are no Connect accounts setup on this machine, offer to add one
# for connect.posit.cloud
if (!'connect.posit.cloud' %in% accounts$server) {
if (readline('Do you want to connect to connect.posit.cloud? (y/n)') == 'y')
rsconnect::connectCloudUser()
publish_book = function(
name = NULL, account = NULL, server = NULL, render = c("none", "local", "server")
) {

# if there are no Connect accounts setup on this machine
# then offer to add one for connect.posit.cloud
accounts <- rsconnect::accounts()
accounts <- subset(accounts, server != "shinyapps.io")
if (is.null(accounts) || nrow(accounts) == 0) {
# see if they want to configure an account (bail if they don't)
message('You do not currently have a publishing account ',
'configured on this system.')
result = readline('Would you like to configure one now? [Y/n]: ')
if (tolower(result) == 'n') return(invisible())

# configure the account
rsconnect::connectCloudUser()
}

# deploy the book
rsconnect::deploySite(siteDir = getwd(), siteName = name, account = account, server = server, ...)
rsconnect::deploySite(
siteDir = getwd(), siteName = name, account = account, server = server,
render = render, logLevel = 'normal'
)
}
26 changes: 18 additions & 8 deletions man/publish_book.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/render_book.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/resolve_refs_html.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading