#' Retrieve a Post
#' @param post the post ID
#' @export
post_retrieve <- function(post) {
send_request("GET", "/posts/{post}")
}
#' View a Post in the Browser
#' @inheritParams post_retrieve
#' @export
post_browse <- function(post) {
response <- send_request("GET", "/posts/{post}", query = list("_fields" = "link"))
url <- response[["content"]][["link"]]
utils::browseURL(url)
}
#' Update a Post
#' @inheritParams post_retrieve
#' @param title post title
#' @param content post content (see [post_content()] for RMarkdown)
#' @param ... Currently unused
#' @export
post_update <- function(post, ..., title = NULL, content = NULL) {
is_post_content <- inherits(content, "wordpress_post_content")
if (inherits(content, "wordpress_post_content")) {
if (is.null(title)) {
try(silent = TRUE, {
title <- rmarkdown::yaml_front_matter(attr(content, "file"))$title
})
}
content <- unclass(content)
}
body <- purrr::compact(
list(
title = title,
content = content
)
)
send_request("POST", "/posts/{post}",
body = body,
encode = "json",
...
)
}
#' Create Post Content from RMarkdown
#' @param file path to .Rmd file
#' @export
post_content <- function(file) {
output_file <- fs::file_temp(ext = "html")
on.exit(unlink(output_file), add = TRUE)
render_wordpress(file, output_file = output_file, quiet = TRUE)
structure(
brio::read_file(output_file),
file = file,
class = "wordpress_post_content"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.