You can install the released version of goodpress from its GitHub repository:
Then you will need to tweaks things once on your website for three aspects
See vignette("setup", package = "goodpress")
.
The summary is: create your posts in folders as index.Rmd with
hugodown::md_document
output format; knit,
wp_post()
, rinse, repeat.
fs::dir_tree(system.file(file.path("post-example2"), package = "goodpress"))
#> /tmp/Rtmp0VRB2o/Rinst11673854fcbe/goodpress/post-example2
#> ├── chicago-fullnote-bibliography.csl
#> ├── figs
#> │ ├── pressure-1.png
#> │ └── unnamed-chunk-1-1.png
#> ├── index.Rmd
#> ├── index.md
#> └── refs.bib
hugodown::md_document
as an output format.wp_post()
that takes the path to the post folder as argument,
create a draft post in your website, uploads all image media stored in
the “figs” folder, edits the references to image media and then
publishes the post.wp_post()
for a folder, it
creates a file called .wordpress.yml
in the post folder,
that contains, in particular, the URL and ID of the post on your
WordPress website. This way, next time the function is run, the post is
updated.Example post and its source. Note that it includes citations as footnotes by using the same strategy as hugodown.
You could have one big “blog” folder/RStudio project with each post as a sub-folder, neatly named YYYY-MM-DD-slug, and at the root of the blog folder you’d have this script you’d run from the RStudio project
wordpress_url <- # your url
today_post <- "2020-06-01-cool-post"
goodpress::wp_post(today_post, wordpress_url)
For plots generated via R, just use R Markdown as you normally would.
For images not generated from R code, save them in the
figs
subfolder and use
knitr::include_graphics()
to include them. See example post with a cat
picture and its
source.
For videos you can embed them using vembedr.
The default status of the post is “publish”. If you want another status (status has to be one of: “publish”, “future”, “draft”, “pending”, “private”) , write it in the yaml (and then knit index.Rmd again) e.g.
---
title: "Title of the Post"
date: "2020-04-01T00:00:00"
slug: "post-slug"
excerpt: "Here I summarize this fantastic post"
status: "private"
output: hugodown::md_document
---
The package cannot handle private posts with password, only private posts that are visible to admins and editors only. You could create a private post, and then from the WordPress interface make it visible with password. Make it private again before trying to update the post with the R package.
First, add MathJax JS script to your website, once.
In every post where you want to use math, use MathJax input (MathML, LaTeX). After formulas put a few empty lines.
See example post with math and its source.
You can add a More
tag for your post if you don’t want to show the whole post on your
homepage. This can be done by adding a
`r goodpress::read_more()`
inline code wherever you want
the More tag to appear in your index.Rmd
post file.
If you’re curious. 🙂
The “one post per folder” thing is inspired by Hugo leaf bundles.
At the moment this package uses the very handy hugodown
’s R
Markdown output format which allows using downlit
for R
syntax highlighting without my having to think too much.
On disk your post is stored as index.Rmd and index.md, but before upload to the WordPress API it is transformed to HTML using Pandoc.
The current best tool for writing from R Markdown to WordPress, knitr::knit2wp()
,
relies on a package that hasn’t been updated in years and that depends
on the no longer recommended RCurl
and
XML
. In the meantime, WordPress gained a REST API that to my
knowledge isn’t wrapped in any working R
package.
There is also the solution to use a plug-in to sync a GitHub repo with a WordPress blog (see this website and its source) but it doesn’t handle media. If you use a GitHub repo: