This website was built using rmarkdown’s site generator. Most of the information here come from there.

Basic website structure

Create a _site.yml file with the following:

name: "LC space"
navbar:
  title: "LC"
  left:
    - text: "About"
      href: index.html
    - text: "Rants"
      href: rants.html
      

Note that the files in the nav have extension html while we will write the pages in md or Rmd files.

Create two files index.md and rants.md with the title, such as:

---
title: "my rants"
---

ciao!

Note that all the Rmd files should be in the root directory!

At this point you can generate the website with the command:

rmarkdown::render_site()

The compiled version will be in the _site folder.
This is the folder that has to be served e.g. with Github pages.

Caching the content

Some Rmd can contain long operations which have to be re-run every time the website is rebuilt. To avoid this, we can place the following R chunk at the beginning of the Rmd notebook.

{r setup, include = FALSE}
knitr::opts_chunk$set(comment = NA, tidy = FALSE, warning = FALSE, message = FALSE, include=T, cache = TRUE)

Create the git repo

  1. Create a new directory _public which will be synchronized with the github repo. This is necessary since the _site folder is deleted and recreated every time, therefore also the .git inside it.

  2. go to _public, initiate a new git, and switch to the gh-pages branch.

git init
git checkout -b gh-pages
  1. cp the whole content of _site inside _public (later this will be automatised in the bash script that pushes the new versions of the website).
cp -r _site/* _public/
  1. create a github repo and do not add the README.md

  2. git add, commit, add remote and push

git add .
git commit -m "golive"
git remote add origin https://github.com/leonardocerliani/ersito.git
git push origin gh-pages
  1. The website is now live at https://leonardocerliani.github.io/ersito/

Add new pages to the website

After creating the page with rmarkdown::render_site() you just need to push the content of the _public folder (which is synchronized to the github repo).

Before that of course you need to copy the whole content of _site - after after rmarkdown::render_site() has completed - to _public. I suggest to automatise the whole thing with a small bash script to be placed and run from the root directory:

_dogit.sh

#!/bin/bash
cp -r _site/*  _public/
cd _public
git add .
git commit -m "golive"
git push origin gh-pages
cd ..

NB: The reason to use the underscore in front of the _public and _dogit.sh is to prevent markdown to copy them to the rendered website directory.

Pulling from the github

If you ever need to pull from the github repo online, remember to pull from the gh-pages branch:

git pull origin gh-pages