5 Steps to Create a Blog with Hugo and R

5 Steps to Create a Blog with Hugo and R
Figure: https://learn.netlify.com/en/shortcodes/attachments/

1. Install blogdown and Hugo

Create a folder for the blog, enter it, and start an R session. The first thing we need to do is to download the blogdown package, which acts as an interface between R and Hugo, a generator for static web pages:

require(blogdown) # load blogdown
install_hugo() # install Hugo framework

2. Customize your blog

Once all the files have been downloaded, you may want to select a theme for your blog. For example, this blog uses Mainroad. If you are looking for a personal page, the Academic theme is very popular. Once you’ve found a theme you like, you can pass the theme as an argument to the new_site function:

new_site(theme = "Vimux/mainroad")

Note that the theme argument is based on the location of the theme’s GitHub repository (e.g. https://github.com/Vimux/mainroad for Mainroad). Upon executing blogdown::serve_site(), a local server offering a preview of your blogdown will be started. As long as the R session is running, the daemon will automatically update the blog when you make local changes to the blog.

Next, configure your blog’s config file (e.g. config.toml) in order to set parameters such as your name, the title of your blog, and so on.

3. Post something

All the posts are stored in the content/post folder. Posts can be stored in Markdown format, or, if you want to include R code, in RMarkdown format. Each post can be configured using by adjusting the Hugo front matter configuration.

4. Create a GitHub repository

Initialize a new GitHub repository for your blog and push the files of your working folder there.

5. Deploy the blog

To host the blog, you can select from free providers such as as Netlify or GitHub Pages. I’m currently using Netlify and its extremely convenient. This is how it works:

  • Register at Netlify
  • Associate Netlify with the blog’s GitHub repository
  • Netlify will automatically build and deploy your blog every time you push to the blog’s GitHub repository

That’s it already! I hope you are having fun with your new blog. If you encounter any problems, you should consider this comprehensive blogdown tutorial. If you don’t find the answer there, don’t hesitate to write a comment!