Your Static Site in R
This is a (very basic) static website generator using R. There are many such generators, some of which handle R code. This is aimed at making R code a first class component of the site. It uses tools available as R packages.
A static website generator takes a bunch of files, usually written in various templating languages, and generates HTML webpages from it. Those HTML files can then be uploaded to any web server. This website generator supports R-centric templating languages (brew, Rmarkdown, Rhtml). In terms of how it works, in takes (heavy) inspiration from Middleman.
The package is not on CRAN (yet) but you can install it using the devtools package
library("devtools") install_github("yssr", "jiho")
Load the package and initialise the website
This creates a directory called
foo and sets your R working directory there. Inside
- a layout file (
source/layouts/main.brew) which defines the skeleton of every page on your site.
- a content file (
source/index.Rmd) which contains the content of the future
Now turn this into a website using
This renders "index.Rmd" into HTML code which is then injected in the layout. The result is stored in the newly created
build directory, next to
source. To view this in a browser, provided you have python with SimpleHTTPServer, use:
The render functions does this sequence of things:
- record all files present in the
- call all R scripts; those scripts may create new content
- get all template files (
Rhml), render the content of each one and inject it into the layout. Store the resulting HTML files in the source directory.
- move everything to the build directory
- remove template files from
buildbecause they are not needed on the actual site
- remove newly created files (HTML but also files created by R scripts) from the
sourcedirectory, to come back to the state before 1.