Converting a Quarto blog post to a Mastodon thread and posting it

mastodon
Author

Gjalt-Jorn Peters

Published

January 11, 2023

This is a Mastodon thread. The original thread is available here:


This thread explains the {quartodon} R πŸ“¦ (see https://quartodon.opens.science).

The #rstats quartodon πŸ“¦ allows you to post a Mastodon thread from a plain text file (e.g., a blog post from a Quarto, {blogdown}, or {distill} website, another Quarto or R Markdown file, or just a plain text file).

This effectively allows you to post blog posts to Mastodon in a thread of toots πŸ“‘βž‘οΈπŸͺ„βž‘️🐘🐘🐘

A GIF of an elephant herd (or, an elephant thread, if you will). I tried to find a GIF of a herd of Mastodons, but to no avail.


The {quartodon} package comes with an RStudio addin with two commands

πŸš€ β€œExtract and preview all toots”

πŸš€ β€œExtract and post all toots”

These take the currently active document, extract all toots, add thread counters, and do some preparation and checking (toot lengths, image sizes, and alt texts) πŸ”πŸ§

When previewing, the thread will be shown in the viewer with character counts and showing any errors πŸͺŸ

When posting, the thread will be posted to Mastodon πŸ“¬

A screenshot of RStudio showing the Addins menu, with the cursor hovering over the 'Extract and preview all toots' option, with the Quarto blog post containing the toots in this thread.


The basic use of {quartodon} is very simple.

1️⃣ You set up your credentiasl with {rtoot} in an environment variable πŸ”

2️⃣ You structure your blog post as a thread of toots 🧡🐘

3️⃣ You preview the toot thread and double check everything βœ…βœ…

4️⃣ You post your thread, et voila πŸ‘Œ

The first post will be posted as β€œpublic” 🌏

The other posts will be replies to each other, and will be posted as β€œunlisted” πŸ”“

A GIF of magician Doug Henning making a flourishing gesture and saying 'Magic' with that text appearing in a sparkly font.


Some details about how it works (this describes the default settings, most are customizable):

πŸ€– Basics πŸ’«

πŸ‘‰ The text is separated into toots by looking for lines containing only β€œ-----” (five dashes).

πŸ‘‰ The first fragment (before the first five dashes) is ignored, allowing you to add stuff to your post that won’t be part of the toot thread.

πŸ‘‰ It automatically adds thread counters to the end of every toot, like this one πŸ‘‡


πŸ€– Images πŸ’«

πŸ‘‰ It checks whether images can be found, and I didn’t implement a check for URLs yet, so images have to be local for now.

πŸ‘‰ Image alt texts are checked for minimum lenght (currently, 10 characters)

πŸ‘‰ For now, only one image can be included (if multiple are included, only the first one is retained


πŸ€– Cleaning πŸ’«

πŸ‘‰ All headings will be removed (all lines starting with #)

πŸ‘‰ All backticks will also be removed (since Markdown uses that to display code, but Mastodon doens’t).

πŸ‘‰ All strings of more than three consequtive newline characters will be replaced by two newline characters


πŸ€– URLs πŸ’«

πŸ‘‰ {quartodon} replaces all URLs with their title, which means that hyperlinks where the title (the part between the square brackets in Markdown) isn’t the URL will just disappear in the toot.

πŸ‘‰ Note that relative URLs will not work from Mastodon; all URLs have to start with β€œhttps?://”, because {quartodon} processes the raw .qmd, .rmd, or .md file, before {Quarto} (or {rmarkdown} or {knitr}) did any replacement work.


πŸ€– Toot character counts πŸ’«

πŸ‘‰ When counting toot lengths, {quartodon} counts all URLs as 23 characters, conform the Mastodon defaults.

πŸ‘‰ When counting toot lengths, it also corrects usernames, stripping the instance information (i.e., the last @ and everything following it (see https://docs.joinmastodon.org/user/posting/).

A screenshow of a part of the thread preview generated by quartodon, showing the fourth toot in this thread with a character count of 350 characters.


You can find the {quartodon} documentation at https://quartodon.opens.science

The vignette from which this Mastodon thread was extracted and posted is located at https://quartodon.opens.science/articles/quartodon_intro.html

If you would like to check out the GitLab repo with the source code, check https://gitlab.com/r-packages/quartodon

Finally, you can check out the Quarto blog post with the same information at https://gjyp.nl/posts/2023-01-converting-a-quarto-blog-post-to-a-mastodon-thread-and-posting-it.html

For now - have fun!

A GIF of an elephant grinnning and the text 'Mastodon. It's nice'.


These are the basics. Of course, this is the first version of the package: who knows what we can add in the future? πŸš€

This package was fun to create, and will hopefully be useful. Hopefully many others can use this to let Quarto (or other) blog posts do double duty as threads of toots posted to Mastodon 🐘

At the same time I’m not sure how much time I’ll have to extend and maintain this, so if this seems like a fun project to you, please drop a line!

A GIF of Dwayne Johnson saying 'We have to do this together'.