Jan Hlavacek
Jan Hlavacek

Reputation: 207

Linking to another post in blogdown

Suppose I have an older post in contents/post/2019-04-29-old-post.Rmd and I want to link to it from a new rmarkdown post. Is there any way to do it without using the hardcoded url of the live site (so that I don't have to change all these cross links when the url of my site changes)?

Right now I do this:

In the [previous post](https://my.si.te/2019/04/29/old-post.html) we covered...

Is there a way to just identify the old post in some way (maybe the Rmd file name) and have blogdown/hugo generate the correct url?

Upvotes: 8

Views: 1300

Answers (1)

Wil
Wil

Reputation: 3178

If you have set your base URL correctly in config.toml like this:

baseurl = "https://my.si.te/"
languageCode = "en-us"
title = "A Hugo website"
theme = "hugo-lithium"
googleAnalytics = ""

and also have set the [permalinks] setting (also in config.toml):

[permalinks]
    post = "/:year/:month/:day/:slug/"

Then the base URL becomes the root folder, so you can link like this:

In the [previous post](/2019/04/29/old-post/) we covered...

the generic form being

In the [previous post](/:year/:month/:day/:slug/) we covered...

Based on the [permalinks] option.

Upvotes: 7

Related Questions