Migrating from Hugo to Quarto

rstats
quarto
blog
We have migrated our blog from Hugo to Quarto! Here are a few quick tips that made the transition a bit smoother.
Author

Lucy D’Agostino McGowan

Published

September 19, 2022

We have migrated our blog from Hugo to Quarto! Here are a few quick tips that made the transition a bit smoother.

1. Setting up a Quarto website

It is super easy to set up a Quarto website. To get the basic template, you can run the following in your terminal:

quarto create-project mysite --type website

You can find lots of details about how to customize your site in the Quarto Docs. The rest of this post will cover a few things that made the transition smooth for us.

2. Moving .Rmd files from Hugo to your new site

In Hugo, my .Rmd files were in the following folder under the main project: content/post. These were often individual files, rather than nested in folders. For my Quarto site, I wanted them in a folder called post and I wanted each post to have it’s only folder with content in a file called index.qmd nested within. I wrote a quick R script to help me do this.

library(fs)

# pull all .Rmd files from my blog
files_rmd <- list.files(
  "~/livefreeordichotomize/content/post",
  pattern = "*.Rmd")
# remove the .Rmd for the folders
folders <- gsub(".Rmd", "", files_rmd)

# pull again, with full names
full_files <- list.files(
  "~/livefreeordichotomize/content/post",
  pattern = "*.Rmd", 
  full.names = TRUE)


# create folders
dir_create(glue::glue("posts/{folders}"))

# copy the .Rmd files into a new folder, named according to the old file name
purrr::walk2(
  full_files, 
  folders, 
  ~file_copy(.x, glue::glue("posts/{.y}/index.qmd")))

4. Comments and Google analytics

It is straightforward to incorporate comments on your blog – our old site used utterance. Likewise, it is simple to add Google Analytics. To use this in Quarto, we can add the following to the website’s global yaml:

website:
  comments: 
    utterances:
      repo: lfod/lfod.github.io
  google-analytics: "UA------"

To see our full setup, check out our GitHub repo: github.com/LFOD/LFOD.github.io

Have other questions? Feel free to leave them in the comments!