Feed RSS en Hugo

Como crear un feed para podcast con HUGO
  • Plantilla para generar un feed en Hugo, pensada para generarse desde un section
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>
<channel>
    <title>{{ with .Title }}{{.}}{{ end }}</title>
    <link>{{ .Permalink }}</link>
    {{ with .Description }}
    <description>{{.}}</description>
    <itunes:summary>{{.}}</itunes:summary>
    <itunes:subtitle>{{.}}</itunes:subtitle>
    {{ end }}
    <generator>Hugo -- gohugo.io</generator>
    {{ with .Site.LanguageCode }}<language>{{.}}</language>{{ end }}
    {{ if not .Date.IsZero }}
    <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 +0000" | safeHTML }}</lastBuildDate>
    {{ end }}
    {{ with .OutputFormats.Get "RSS" }}
        {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
    {{ end }}
    {{ with .Site.Author.email }}
        <managingEditor>{{.}} {{ with $.Site.Author.name }}({{.}}){{ end }}</managingEditor>
        <webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{ end }}</webMaster>
    {{ end }}
    {{ with .Site.Copyright }} <copyright>{{.}}</copyright> {{ end }}
    <image>
        <url>{{.CurrentSection.Permalink}}logo_podcast.png</url>
        <title>{{ with .Title }}{{.}}{{ end }}</title>
        <link>{{ .Permalink }}</link>
    </image>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <itunes:explicit>no</itunes:explicit>
    <itunes:category text="Technology" />
    <itunes:category text="News">
        <itunes:category text="Tech News" />
    </itunes:category>
    <itunes:image href="{{.CurrentSection.Permalink}}logo_podcast.png" />
    {{ with .Site.Author.name }}
        <itunes:author>{{.}}</itunes:author>
        <itunes:owner>
            <itunes:name>{{.}}</itunes:name>
    {{ end }}
    {{ with .Site.Author.email }}<itunes:email>{{.}}</itunes:email>
        </itunes:owner>
    {{ end }}
    {{ range $i, $pg := .Pages }}
    <item>
        <title>{{ $pg.Params.title }}</title>
        <link>{{ .Permalink }}</link>
        <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 GMT" | safeHTML }}</pubDate>
        <guid isPermaLink="false">{{ $pg.Params.title }}</guid> 
            {{ with .Params.podcast.mp3 }}
                {{ $file_stat := os.Stat (add "/static/images/" (. | relURL)) }}<enclosure url="{{ . | absURL }}" length="{{ $file_stat.Size }}" type="image/png" />
            {{ end }}
        {{ if .Params.podcast.audio }}
        <enclosure url="{{.Params.podcast.audio}}.ogg" length="{{ with .Params.podcast.olength -}} {{.}} {{- else -}} 0 {{- end }}" type="audio/ogg" />
        <enclosure url="{{.Params.podcast.audio}}.mp3" length="{{ with .Params.podcast.mlength -}} {{.}} {{- else -}} 0 {{- end }}" type="audio/mpeg" />
            {{ with .Params.podcast.iduration }}
        <itunes:duration>{{.}}</itunes:duration>
            {{ end }}
        {{ end }}
        {{ printf "<description><![CDATA[%s]]></description>" .Summary | safeHTML }}
        {{ printf "<content:encoded><![CDATA[%s]]></content:encoded>" .Content | safeHTML }}
            {{ with .Params.podcast.mp3 }}
                {{ $file_stat := os.Stat (add "/static" (. | relURL)) }}<enclosure url="{{ if $.Site.Params.Podcast.cdn }}{{ add $.Site.Params.Podcast.cdn (. | relURL) }}{{ else }}{{ . | absURL }}{{ end }}" length="{{ $file_stat.Size }}" type="audio/mpeg" />
            {{ end }}
            {{ with .Params.podcast.aud }}
                {{ $file_stat := os.Stat (add "/static/Linux-Express" (. | relURL)) }}<enclosure url="{{ . | absURL }}" length="{{ $file_stat.Size }}" type="audio/mpeg" />
            {{ end }}
        {{ with .Site.Author.email }}
            <author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{ end }}</author>
        {{ end }}
        <itunes:explicit>no</itunes:explicit>
        <itunes:title>{{ $pg.Params.title }}</itunes:title>
        <itunes:subtitle>{{ .Summary | plainify | truncate 230 }}</itunes:subtitle>
        <itunes:summary>{{ .Content | plainify | htmlUnescape | truncate 3950 }}</itunes:summary>
        <itunes:image href="{{.Site.BaseURL}}images/{{.Params.img}}"></itunes:image>
        {{ with .Site.Author.name }}<itunes:author>{{.}}</itunes:author>{{ end }}
    </item>
    {{ end }}
</channel>
</rss>

Modulos

  • Soportados por AntennaPod:
    • RSS2: channel item guid title link description pubDate enclosure {url,length,type} image {url} language
    • atom: … link {href,rel,type,title,length} …
    • content: encoded -> Para contenido con HTML si “description” no es más largo
    • dc: date
    • itunes: image {href} author duration subtitle summary
    • media: content url fileSize type duration isDefault medium {image,audio,video} description {type}
    • simple-chapters: chapters {chapter} {start,title,href,image}

En uso

Sin uso

Validators

Docu

Ejemplos

Hugo

Duración del audio

    <enclosure url="{{ $pg.Params.link }}" type="audio/mpeg" length="0" />
  • Sacandolo del Params
    {{ $audio_name_arr := split (index .Params.audio 0) "." }}
    {{ $audio_type := index $audio_name_arr (sub (len $audio_name_arr) 1) }}
    {{ $audio_size := 0 }}
    {{- if .Params.audio_size }}{{ $audio_size = int .Params.audio_size }} {{ end -}}
    <enclosure url="{{ index .Params.audio 0 | absURL }}" length="{{ $audio_size }}" type="audio/{{ $audio_type }}" />
    <enclosure url="{{ .Site.Params.media_prefix }}{{ .Params.podcast_file }}" {{with .Params.podcast_bytes}}length="{{ . }}"{{ end }} type="audio/mpeg" />

Ejemplos

Foros

Última modificación 2022.19.03: npm install --save-dev (335619f)