Workbench

Using the Eleventy RSS Plugin with `pathPrefix`

This site (at the time of this post, anyway) is hosted on a tilde and as such every resource on it has a URI beginning with /~moondog8.

pathPrefix

Eleventy provides a config option called pathPrefix for this scenario.

absoluteUrl

The Eleventy RSS Plugin provides a filter called absoluteUrl that you can use to prepend your site's domain name to any page links that appear in your RSS feed.

absoluteUrl with pathPrefix

When trying to get an RSS feed for this site working, I used one of the sample feed templates and all of the permalinks were broken; absoluteUrl has no awareness of pathPrefix, and it took me a minute to figure out how to get them working.

The Solution

In a nutshell: Anywhere in your RSS template that you see a link being passed to the absoluteUrl filter, ie:

{{ permalink | absoluteUrl(metadata.url) }}

or

{%- set absolutePostUrl = post.url | absoluteUrl(metadata.url) %}

Send it through the url filter* first:

{%- set absolutePostUrl = post.url | url | absoluteUrl(metadata.url) %}

*I haven't tried this with the newer HTMLBase element, but if I read the documentation correctly, you should be able to use:

{%- set absolutePostUrl = post.url | htmlBaseUrl | absoluteUrl(metadata.url) %}

Mon Nov 20 2023 19:00:00 GMT-0500 (Eastern Standard Time)