I was able to add basic password protection for one page on my website using Brent Scott's pagecryptr
package, which is a R-wrapper for PageCrypt. The set up is very simple thanks to the R package.
- Create the password protected version of the RMD file, knit it to HTML, and save it somewhere (literally anywhere, but I put it on my private repository on GitHub). We'll call this file
password.html
.
- Name the page you want to password protect in your TOML file. Mine looks like this:
[[menu.main]]
name = "Portfolio"
url = "/Portfolio/"
Note that you do not need to create a RMD or HTML file for this page because we'll be using pagecryptr
to create it.
- Install
pagecryptr
install.packages("drat")
drat::addRepo("brentscott93")
install.packages("pagecryptr")
library(pagecryptr)
- In a different R script, run
pagecryptr
to password protect the file:
if(interactive()){
file <- "~/password.html"
pagecryptr(file, "password123", out_file = "~/content/Portfolio.html")
}
Notice how pagecryptr
is taking the file we want to password protect (password.html
) and writing HTML for it that corresponds to the page we created in our TOML (Portfolio.html
). The second argument contains the password you want to use for the website (in this example, it's password123
).
Commit Portfolio.html
to GitHub and you will have a password protected page on your website!