Deprecation of Page.RSSLink in Hugo

I’ve been working towards fixing the following warning with Hugo in the Pure theme. This warning shows up in other themes as well.

ERROR 2022/01/17 23:19:33 Page.RSSLink is deprecated and will be removed in Hugo 0.93.0. Use the Output Format's link, e.g. something like:
{{ with .OutputFormats.Get "RSS" }}{{ .RelPermalink }}{{ end }}

The code looks like this

{{ if .RSSLink -}}
    <link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
    <link href="{{ " podcast.xml " | absURL }}" rel="alternate" type="application/rss+xml" title="Podcast" />
    <link rel="alternate" type="application/json" title="{{ .Site.Title }}" href="{{ " feed.json " | absURL }}" />
    <link rel="EditURI" type="application/rsd+xml" href="{{ " rsd.xml " | absURL }}" />
{{ end -}}

I originally tried to turn it into the following but it wasn’t rendering properly when I sent it to micro.blog.

{{ range .AlternativeOutputFormats -}}
 {{ printf `<link href="%s" rel="%s" type="%s" title="%s" />` .Permalink .Rel .MediaType.Type $.Site.Title | safeHTML }}

{{ end -}}

Ultimately, I used the following code.

<!-- RSS etc -->
{{- if .OutputFormats.Get "RSS" -}}
{{- with .OutputFormats.Get "RSS" -}}
<link href="{{ .RelPermalink }}" rel="alternate" type="application/rss+xml" title="{{ $.Site.Title }}" />
<link href="{{ .RelPermalink }}" rel="alternate" type="application/rss+xml" title="{{ $.Site.Title }}" />
<link href="{{ "podcast.xml" | absURL }}" rel="alternate" type="application/rss+xml" title="Podcast" />
<link rel="alternate" type="application/json" title="{{ $.Site.Title }}" href="{{ "feed.json" | absURL }}" />
<link rel="EditURI" type="application/rsd+xml" href="{{ "rsd.xml" | absURL }}" />
{{- end -}}
{{ end -}}

I wanted to have you all look at it for a little bit and ask the question if it is safe to assume that all podcast will have the same URL and should I make the title for the podcast the same as the site title.

Is there a way to find what variables that micro.blog gives to the theme?

Link to branch

If you want, you can skip the outer if block. with takes care of that for you:

An alternative way of writing an if statement and then referencing the same value is to use with instead. with rebinds the context ( . ) within its scope and skips the block if the variable is absent, unset or empty.

Yes, I think so, in practice. In theory, though, anyone can dream up another URL or have multiple feeds via custom themes or plug-ins.

That’s a good default, but you might want to look for and use .Site.Params.podcast_title if it’s present. That would add support for people using @manton’s plug-in Podcast title.

This is helpful when debugging templates: What Variables are Available in this Context?

Thank you! I went with the following.

{{- with .OutputFormats.Get "RSS" -}}
<link rel="alternate" type="application/rss+xml" title="{{ $.Site.Title }}"  href="{{ .RelPermalink }}"/>
{{- with $.Site.Params.podcast_title }}
<link rel="alternate" type="application/rss+xml" title="{{ . }}"  href="{{ "podcast.xml" | absURL }}" />
{{ else }}
<link rel="alternate" type="application/rss+xml" title="Podcast" href="{{ "podcast.xml" | absURL }}" />
{{ end -}}
<link rel="alternate" type="application/json" title="{{ $.Site.Title }}" href="{{ "feed.json" | absURL }}" />
<link rel="EditURI" type="application/rsd+xml" href="{{ "rsd.xml" | absURL }}" />
{{- end -}}

I think I’ll spend some time just nitpicking at whitespace in the template for a while.