Use shortcodes to embed tweets, videos, etc. in your blogdown blog posts

March 31, 2018
By

(This article was first published on reigo.eu, and kindly contributed to R-bloggers)

Shortcodes are simple snippets inside your content files calling built-in or custom templates. This short post is a shout-out for the blogdown::shortcode() function. Example(s) of blogdown::shortcode() can be found in blogdown book. To learn more about shortcodes visit https://gohugo.io/content-management/shortcodes/.

Shortcodes make it super easy to embed content in blog posts. Lets say we have a video we want to embed in a post: https://youtu.be/CjTLN-FXiFA. By adding

```{r, eval=TRUE}
blogdown::shortcode("youtube", "CjTLN-FXiFA")
```

to our .Rmd file, we get:

How I discovered shortcodes

For some time I have had the routine of (scrolling twitter and) sending tweets holding information I see myself using to my e-mail. For example, I find @rensa_co’s example of dplyr::case_when() and geom_text() to be quite useful:

So I sent it to my (work or personal – I’m not sure which) e-mail with hopes to easily find it in the future. One can experience the pain of the e-mail system after first time really looking for something. One can quickly understand that there must exist a better way. As I was looking for a way to archive all these pearls, I was thinking about devoting a blog post to those tweets. I started by looking for a way to embed twitter cards to blog post written with blogdown. I googeled “how to embed tweet in rmarkdown” which not surprisingly lead me to stackoverflow. This question was answered by Yihui and pointed to the blogdown documentation where I learned about shortcode() function.

FIN

After giving the blog post approach a second thought I realized that this is probably not gonna work. It seemed to be too much hassle to update the post manually or figure out how to automate the process. I ended up creating a #rhtwotes (rh – my initials; twote1 – twitter note/quote) and the plan is to retweet things I see myself using with #rhtwotes hashtag. This gives me easy access to my twotes whenever I have internet connections and also simplifies (retweeting is easier than sending an e-mail) note taking part.

For now, using the hashtag system feels quite natural and optimal way to cover my use case. I also ask myself: “How could I use something not as simple as retweeting system before?”. As it often happens, obvious solutions for our problems become obvious only after we have tried many not so obvious ones.

#rhtwotes


  1. I first had tnotes for twitter notes in mind. Fortunately ML proposed twote which has much better sounding. Word twote seems to have wider usage as well: https://www.urbandictionary.com/define.php?term=Twote

To leave a comment for the author, please follow the link and comment on their blog: reigo.eu.

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)