Moving from Blogdown to Quarto

R
Blogdown
Quarto
Pelican
What worked and what didn’t work immediately, and how to get everything running.
Author

Mauricio “Pachá” Vargas S.

Published

May 29, 2023

R and Shiny Training: If you find this blog to be interesting, please note that I offer personalized and group-based training sessions that may be reserved through Buy me a Coffee. Additionally, I provide training services in the Spanish language and am available to discuss means by which I may contribute to your Shiny project.

Motivation

Recently, I have to run blogdown::serve_site() and blogdown::build_site several times to get my new posts rendered. I don’t know why, but it was a bit annoying.

I already have a one liner to install Quarto, so I decided to give it a try.

Note: I started using computers in the old DOS days, so I use the terminal more than the average user.

Install Quarto

I installed Quarto with sudo apt install quarto (I use Linux Mint). To do this, you can visit my repository containing binaries for RStudio Desktop and Quarto.

Create a new project

From RStudio I created a new “Quarto Blog” project, there I copied the complete contents folder from my Blogdown project.

Moving images and other files

With Blogdown I had folders of the form static/YYYY-MM-DD/post-title with all the images and other files for each post, and I had to move them to each post’s folder and inside img/, pdf/, etc.

Without this change, the images were not rendered and links were incorrect.

For each post that required it I had to change the links of the form

<img src="/blog/images/2017-10-13-rick-and-morty-tidy-data/rick-and-morty.jpg"></img>

to

<img src="img/rick-and-morty.jpg"></img>

I did this manually.

Updating posts headers

Quarto uses description instead of summary in the YML headers, so I had to change this in each post.

My last C++ post’s header was

---
title: Cpp11 (R package) vendoring
authors: Mauricio "Pachá" Vargas S.
date: 2023-05-23
categories: "Data Science"
tags: ["R", "VSCode", "Linear models", "C++", "Linux"]
summary: Copying the code for the dependencies into my project’s source tree.
---

I changed it to

---
title: Cpp11 (R package) vendoring
authors: Mauricio "Pachá" Vargas S.
date: 2023-05-23
categories: ["R", "VSCode", "Linear models", "C++", "Linux"]
description: Copying the code for the dependencies into my project’s source tree.
---

To do this for each post I created a bash script titled contents/02-update-posts-headers.sh with this content.

#!/bin/bash

# for each qmd file, replace the first occurence of "summary: " with "description: "
for file in $(find . -name "*.qmd"); do
    sed -i '0,/summary: /s//description: /' $file
done

# for each qmd file, delete the first line starting with "categories: "
for file in $(find . -name "*.qmd"); do
    sed -i '/categories: /d' $file
done

# for each qmd file, replace the 1st occurrence of "tags: " with "categories: "
for file in $(find . -name "*.qmd"); do
    sed -i '0,/tags: /s//categories: /' $file
done

From the terminal I run this.

bash 02-update-posts-headers.sh

Generating an XML feed (optional)

Because the blog is listed in R-Bloggers, I had to generate a new XML feed, something that blogdown did automatically.

I edited index.qmd in the root of the project and modified the listing part YML header by adding feed: true.

listing:
  contents: "."
  sort: "date desc"
  type: default
  categories: true
  sort-ui: false
  filter-ui: false
  feed: true

Final comment

I am surprised that, besides images and links, everything else worked out of the box. My blog goes back to 2015, when I was starting with R, and I have a lot of posts with a lot of code.

With the exception of two posts that I did not keep copies of the data and that I had to exclude, everything else worked after installing missing R packages. Probably it would have been better to include codes and results as markdown chunks, but I did not know about this when I started blogging.

Also, this blog is not very popular, so I don’t have to worry about breaking links, but I kept most of them. When I started blogging in 2015 I was using Pelican, and I exported the R Markdown outputs as Markdown files to then render the blog with Python. In 2017 I switched to Blogdown, and now I am using Quarto. It has been a long journey!

References