blogdown Part I: Launching a New Site

June 18, 2018
By

(This article was first published on Ye Olde R Blog Grogram, and kindly contributed to R-bloggers)

Purpose

  • A basic workflow to set up an R blog using blogdown.
    • Create using the Hugo theme Tranquilpeak (v0.4.3).
    • Host static website on Netlify
    • Source files stored on github
    • Configured so that RSS feed can be shared with R-bloggers

Disclaimer

Instructions here will rarely be explicit. These workflows are essentially notes for experienced users to help remind them of the minimal steps to complete the task at hand.

Prerequisites

  • Strongish familiarity with RStudio, R packages, and R projects
  • Medium familiarity with git and github
  • Some familiarity with blogdown
  • Installation of R, R-Studio, blogdown, and all associated dependencies
  • A Netlify account linked to Github

Workflow

  • Start project
    • RStudio toolbar:
      • File -> New Project -> New Directory -> blogdown website
      • Copy kakawait/hugo-tranquilpeak-theme into the Hugo theme field
  • Version control
    • RStudio toolbar:
      • Tools -> Project Options -> Version Control -> select git
    • Add the line public to .gitignore
    • Track all project files:

      git add --all
      git commit -am "First commit"
    • Create a new repository on github
    • Link local repo to remote repo:

      git remote add origin [email protected]:username/blogname.git
      git push -u origin master
  • Nelify
    • Add following line to config.toml file:
      • ignoreFiles = ["\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"]
    • Go to Netlify and select New site from Git
    • Set the following options:
      • Build command: hugo
      • Publish directory: public
    • Change build variables:
      • Find local hugo version blogdown::hugo_version()
      • Settings -> Build and Deploy -> Build Environmental Variables
      • Set key -> HUGO_VERSION and value -> 0.42.1 (or the appropriate version)
    • Change to desired site name:
      • On Netlify: Settings -> Site details -> Site information -> Site name
  • config.toml
    • Update baseURL to netlify address
    • Make other changes as desired
  • RSS feed
    • Note: By default, the RSS feed for Tranquilpeak is set up to display article summaries, which will not allow automatic uploading to R-bloggers. A solution (reproduced here) can be found on the blog: cool but useless
    • Create the file rss.xml in the following directory:
    • themes/hugo-tranquilpeak-theme/layouts
    • Copy and paste the following text into this file (unmodified version here):

      
        
          {{ if eq  .Title  .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}
          {{ .Permalink }}
          Recent content {{ if ne  .Title  .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}
          Hugo -- gohugo.io{{ with .Site.LanguageCode }}
          {{.}}{{end}}{{ with .Site.Author.email }}
          {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Author.email }}
          {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Copyright }}
          {{.}}{{end}}{{ if not .Date.IsZero }}
          {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }}
          {{ with .OutputFormats.Get "RSS" }}
              {{ printf "" .Permalink .MediaType | safeHTML }}
          {{ end }}
          {{ range .Data.Pages }}
          
            {{ .Title }}
            {{ .Permalink }}
            {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}
            {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}
            {{ .Permalink }}
            {{ .Content | html }}
          
          {{ end }}
        
      
    • Potential alternative solution by Thug R Life

  • Add description to .Rmd posts

    • Note: posts created using .Rmd documents will be formatted awkwardly on the homepage (by default, show the first 70 lines all combine into one paragraph). github user Joseph Chou (jhchou), posted a solution that works for Tranquilpeak v0.4.3-BETA.
    • Navigate to themes\hugo-tranquilpeak-theme\layouts\_default\summary.html
    • Find line 43 – {{ .Summary }}
    • Replace with:

      {{if .Description }}
        {{ printf "%s" .Description }}
      {{ else }}
        {{ printf "%s" .Summary | markdownify }}
      {{ end }}
    • This will allow you to add summaries via the .Rmd post YAML header that will display the first 70 lines

      ---
      title: "Test post 2"
      author: ''
      date: '2018-06-19'
      slug: test-post-2
      categories: []
      tags: []
      description: "a description"
      ---
  • Deploy website
    • Netlify will build website in public upon push to github.

Other themes

This workflow was written with the Tranquilpeak theme in mind. However, other suitable themes may be found here:

To implement another theme, when starting a new blogdown website, identify the user name and rep of the desired theme, and use this as prompted when starting a new website using the File menu in RStudio.

To leave a comment for the author, please follow the link and comment on their blog: Ye Olde R Blog Grogram.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)