This commit is contained in:
Florian Maury 2024-10-16 15:38:07 +02:00
parent 52e4d2eca4
commit 44190c8913
5 changed files with 381 additions and 108 deletions

View file

@ -0,0 +1,9 @@
{{- $indent := collections.Index . "indent" -}}
{{- $ctx := collections.Index . "context" -}}
{{- range $ctx -}}
{{- strings.Repeat $indent " " -}}
<podcast:funding url="{{- .url | transform.XMLEscape -}}">
{{- .comment | transform.XMLEscape -}}
</podcast:funding>
{{- "\n" -}}
{{- end -}}

View file

@ -0,0 +1,27 @@
{{- $indent := collections.Index . "indent" -}}
{{- $ctx := collections.Index . "context" -}}
{{- range $ctx -}}
{{- strings.Repeat $indent " " -}}
<podcast:person role="
{{- collections.Index . "role" | transform.XMLEscape -}}
" group="
{{- collections.Index . "group" | transform.XMLEscape -}}
" img="
{{- $image := collections.Index . "image" -}}
{{- with collections.Index $image "external_url" -}}
{{- . | transform.XMLEscape -}}
{{- else -}}
{{- $resource_file := collections.Index $image "resource_file" -}}
{{- with resources.Get $resource_file -}}
{{- .Permalink | transform.XMLEscape -}}
{{- else -}}
{{- errorf "failed to get resource %q" $resource_file -}}
{{- end -}}
{{- end -}}
" href="
{{- collections.Index . "href" | transform.XMLEscape -}}
">
{{- collections.Index . "name" | transform.XMLEscape -}}
</podcast:person>
{{- "\n" -}}
{{- end -}}

View file

@ -0,0 +1,11 @@
{{- $indent := collections.Index . "indent" -}}
{{- $ctx := collections.Index . "context" -}}
{{- range $ctx -}}
{{- strings.Repeat $indent " " -}}
<podcast:recommendations url="
{{- collections.Index . "url" | transform.XMLEscape -}}
" type="application/json" language="
{{- collections.Index . "language" | transform.XMLEscape -}}
" />
{{- "\n" -}}
{{- end -}}

View file

@ -0,0 +1,13 @@
{{- $indent := collections.Index . "indent" -}}
{{- $ctx := collections.Index . "context" -}}
{{- range $ctx -}}
{{- strings.Repeat $indent " " -}}
<podcast:socialInteract protocol="
{{- collections.Index . "protocol" | transform.XMLEscape -}}
" uri="
{{- collections.Index . "uri" | transform.XMLEscape -}}
" priority="
{{- collections.Index . "priority" | transform.XMLEscape -}}
" />
{{- "\n" -}}
{{- end -}}

View file

@ -1,30 +1,52 @@
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://podcastindex.org/namespace/1.0" version="2.0">
<channel>
<title>{{ .Title | transform.XMLEscape }}</title>
<description>{{ .Description | transform.XMLEscape}}</description>
<generator>Hugo (with git.broken-by-design.fr/fmaury/podcast-mod)</generator>
<lastBuildDate>{{ time.Now.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</lastBuildDate>
<language>{{ .Language.Lang }}</language>
{{- with .Params.copyright }}
<copyright>{{ . | transform.XMLEscape }}</copyright>
{{- end }}
<itunes:image>
{{- $podcast_type := "" -}}
{{- /* Either external_url or resource_file must be defined; use external_url if it is defined. If not, get the resource designated by the resource_file paramter. The resource identifier must be relative to the podcast directory */ -}}
{{- $image := "" -}}
{{- if collections.Index .Params.image "external_url" -}}
{{- collections.Index .Params.image "external_url" | transform.XMLEscape -}}
{{- else if collections.Index .Params.image "resource_file" -}}
{{- with collections.Index .Params.image "resource_file" | .Resources.Get -}}
{{- .Permalink -}}
{{- $image = .Permalink -}}
{{- else -}}
{{- errorf "failed to fetch resource %q" (collections.Index .Params.image "resource_file") -}}
{{- end -}}
{{- else -}}
{{- errorf "empty image parameter on the podcast %q definition" .Title -}}
{{- end -}}
{{- $indent := 2 -}}
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://podcastindex.org/namespace/1.0" version="2.0">
<channel>
<title>
{{- .Title | transform.XMLEscape -}}
</title>
<description>
{{- .Description | transform.XMLEscape -}}
</description>
<generator>Hugo (with git.broken-by-design.fr/fmaury/podcast-mod)</generator>
<lastBuildDate>
{{- time.Now.Format "Mon, 02 Jan 2006 15:04:05 MST" -}}
</lastBuildDate>
<language>
{{- .Language.Lang -}}
</language>
<itunes:image>
{{- $image -}}
</itunes:image>
<itunes:explicit>{{ .Params.explicit | transform.XMLEscape }}</itunes:explicit>
<podcast:guid>{{ .Params.guid | transform.XMLEscape }}</podcast:guid>
{{- "\n" -}}
{{- with .Params.copyright -}}
{{- strings.Repeat $indent " " -}}
<copyright>
{{- . | transform.XMLEscape -}}
</copyright>
{{- "\n" -}}
{{- end -}}
{{- /* Categories are restricted to a set of values. The acceptable values are listed here: https://github.com/Podcastindex-org/podcast-namespace/blob/main/categories.json */ -}}
{{- /* The following code ensures the attribute is set (Apple requires it) and validates the value against the list of acceptable values */ -}}
{{- with .Params.category }}
{{- $category := "" -}}
{{- $categories := resources.Get "categories.json" | transform.Unmarshal -}}
{{- $categoryFound := 0 -}}
{{- range ( collections.Index $categories "Categories") -}}
@ -32,42 +54,88 @@
{{- $categoryFound = 1 -}}
{{- end -}}
{{- end -}}
{{- if $categoryFound }}
<itunes:category>{{ . | transform.XMLEscape }}</itunes:category>
{{- if $categoryFound -}}
{{- strings.Repeat $indent " " -}}
<itunes:category>
{{- . | transform.XMLEscape -}}
</itunes:category>
{{- "\n" -}}
{{- else -}}
{{- errorf "could not find %q in known categories" . -}}
{{- end -}}
{{- else -}}
{{- errorf "missing category definition for podcast %q" .Title -}}
{{- end }}
{{- end -}}
{{- with .Params.website_link }}
<link>{{ . | transform.XMLEscape }}</link>
{{- end }}
<itunes:explicit>{{ .Params.explicit | transform.XMLEscape }}</itunes:explicit>
{{- with .Params.author }}
<itunes:author>{{ . | transform.XMLEscape }}</itunes:author>
{{- end }}
{{- with .Params.podcast_type }}
<itunes:type>{{ . | transform.XMLEscape }}</itunes:type>
{{- end }}
{{- if and .Params.author .Params.email }}
{{- strings.Repeat $indent " " -}}
<link>
{{- . | transform.XMLEscape -}}
</link>
{{- "\n" -}}
{{- end -}}
{{- with .Params.author -}}
{{- strings.Repeat $indent " " -}}
<itunes:author>
{{- . | transform.XMLEscape -}}
</itunes:author>
{{- "\n" -}}
{{- end -}}
{{- with .Params.podcast_type -}}
{{- $podcast_type = . -}}
{{- strings.Repeat $indent " " -}}
<itunes:type>
{{- . | transform.XMLEscape -}}
</itunes:type>
{{- "\n" -}}
{{- end -}}
{{- if and .Params.author .Params.email -}}
{{- strings.Repeat $indent " " -}}
<itunes:owner>
<itunes:name>{{ .Params.author | transform.XMLEscape }}</itunes:name>
<itunes:email>{{ .Params.email | transform.XMLEscape }}</itunes:email>
{{- "\n" -}}
{{- strings.Repeat (add $indent 1) " " -}}
<itunes:name>
{{- .Params.author | transform.XMLEscape -}}
</itunes:name>
{{- "\n" -}}
{{- strings.Repeat (add $indent 1) " " -}}
<itunes:email>
{{- .Params.email | transform.XMLEscape -}}
</itunes:email>
{{- "\n" -}}
{{- strings.Repeat $indent " " -}}
</itunes:owner>
{{- end }}
<podcast:guid>{{ .Params.guid | transform.XMLEscape }}</podcast:guid>
{{- if and .Params.email .Params.locked }}
<podcast:locked owner="{{ .Params.email | transform.XMLEscape }}">{{ .Params.locked | transform.XMLEscape }}</podcast:locked>
{{- end }}
{{- with .Params.medium }}
<podcast:medium>{{ . | transform.XMLEscape }}</podcast:medium>
{{- end }}
{{- with .Params.licence }}
<podcast:licence url="{{ .url | transform.XMLEscape }}">{{ .name | transform.XMLEscape }}</podcast:licence>
{{- end }}
{{- with .Params.images }}
<podcast:images srcset="
{{- "\n" -}}
{{- end -}}
{{- if and .Params.email .Params.locked -}}
{{- strings.Repeat $indent " " -}}
<podcast:locked owner="{{ .Params.email | transform.XMLEscape }}">
{{- .Params.locked | transform.XMLEscape -}}
</podcast:locked>
{{- "\n" -}}
{{- end -}}
{{- with .Params.medium -}}
{{- strings.Repeat $indent " " -}}
<podcast:medium>
{{- . | transform.XMLEscape -}}
</podcast:medium>
{{- "\n" -}}
{{- end -}}
{{- with .Params.licence -}}
{{- strings.Repeat $indent " " -}}
<podcast:licence url="{{- .url | transform.XMLEscape -}}">
{{- .name | transform.XMLEscape -}}
</podcast:licence>
{{- "\n" -}}
{{- end -}}
{{- with .Params.images -}}
{{- $image_url_list := slice -}}
{{- range . -}}
{{- $entry := . -}}
@ -82,84 +150,229 @@
{{- $attr := printf "%s %sw" $url $width -}}
{{- $image_url_list = append $attr $image_url_list -}}
{{- end -}}
{{- delimit $image_url_list "," -}}
"></podcast:images>
{{- end }}
{{- with .Params.funding -}}
{{- range . }}
<podcast:funding url="{{ .url | transform.XMLEscape }}">{{ .comment | transform.XMLEscape }}</podcast:funding>
{{- strings.Repeat $indent " " -}}
<podcast:images srcset="{{- delimit $image_url_list "," -}}" />
{{- "\n" -}}
{{- end -}}
{{- end }}
{{- with .Params.location }}
{{- with .Params.funding -}}
{{- partial "funding.rss.xml" (dict "context" . "indent" $indent) -}}
{{- end -}}
{{- with .Params.location -}}
{{- strings.Repeat $indent " " -}}
<podcast:location geo="{{ collections.Index . "geo" | transform.XMLEscape }}" osm="{{ collections.Index . "osm" | transform.XMLEscape }}">{{ collections.Index . "description" | transform.XMLEscape }}</podcast:location>
{{- end }}
{{- "\n" -}}
{{- end -}}
{{- with .Params.trailer -}}
{{- range . -}}
{{- $season_attr := "" -}}
{{ $url := ""}}
{{- $url := "" -}}
{{- with collections.Index . "resource_file" | $.Resources.Get -}}
{{- $url = .Permalink -}}
{{- else -}}
{{- $url = collections.Index . "external_url" -}}
{{- end -}}
<podcast:trailer pubdate="
{{- collections.Index . "pubdate" | transform.XMLEscape -}}
" url="
{{- $url -}}
" length="
{{- collections.Index . "length" | transform.XMLEscape -}}
" type="{{- collections.Index . "type" | transform.XMLEscape -}}"
{{- if collections.Index . "season" }} season="{{- collections.Index . "season" | transform.XMLEscape -}}"
{{- strings.Repeat $indent " " -}}
<podcast:trailer
{{- " " -}}
pubdate="{{- collections.Index . "pubdate" | transform.XMLEscape -}}"
{{- " " -}}
url="{{- $url -}}"
{{- " " -}}
length="{{- collections.Index . "length" | transform.XMLEscape -}}"
{{- " " -}}
type="{{- collections.Index . "type" | transform.XMLEscape -}}"
{{- if collections.Index . "season" -}}
{{- " " -}}
season="{{- collections.Index . "season" | transform.XMLEscape -}}"
{{- end -}}
>{{- collections.Index . "title" | transform.XMLEscape -}}</podcast:trailer>
>
{{- collections.Index . "title" | transform.XMLEscape -}}
</podcast:trailer>
{{- "\n" -}}
{{- end -}}
{{- end }}
{{- with .Params.social_interacts }}
{{- range . -}}
<podcast:socialInteract protocol="
{{- collections.Index . "protocol" | transform.XMLEscape -}}
" uri="
{{- collections.Index . "uri" | transform.XMLEscape -}}
" priority="
{{- collections.Index . "priority" | transform.XMLEscape -}}
" />
{{- end -}}
{{- end }}
{{- with .Params.podroll }}
{{- with .Params.social_interacts -}}
{{- partial "socialInteracts.rss.xml" (dict "context" . "indent" $indent) -}}
{{- end -}}
{{- with .Params.podroll -}}
{{- strings.Repeat $indent " " -}}
<podcast:podroll>
{{- range . }}
<podcast:remoteItem feedGuid="
{{- collections.Index . "feed_guid" -}}
" feedUrl="
{{- collections.Index . "feed_url" -}}
" medium="
{{- collections.Index . "medium" -}}
" title="
{{- collections.Index . "title" -}}
" />
{{- end }}
{{- range . -}}
<podcast:remoteItem
{{- " " -}}
feedGuid="{{- collections.Index . "feed_guid" -}}"
{{- " " -}}
feedUrl="{{- collections.Index . "feed_url" -}}"
{{- " " -}}
medium="{{- collections.Index . "medium" -}}"
{{- " " -}}
title="{{- collections.Index . "title" -}}" />
{{- "\n" -}}
{{- end -}}
</podcast:podroll>
{{- end }}
{{- with .Params.update_frequency }}
<podcast:updateFrequency {{ if collections.Index . "complete" -}}
{{- "\n" -}}
{{- end -}}
{{- with .Params.update_frequency -}}
{{- strings.Repeat $indent " " -}}
<podcast:updateFrequency
{{- if collections.Index . "complete" -}}
{{- " " -}}
complete="true"
{{- else -}}
{{- $dtstart := collections.Index . "dtstart" -}}
rrule="{{- collections.Index . "rrule" | transform.XMLEscape -}}" {{ if $dtstart -}}
{{- " " -}}
rrule="{{- collections.Index . "rrule" | transform.XMLEscape -}}"
{{- if $dtstart -}}
{{- " " -}}
dtstart="{{- $dtstart | transform.XMLEscape -}}"
{{- end -}}
{{- end -}}
>{{- collections.Index . "description" | transform.XMLEscape -}}</podcast:updateFrequency>
{{- end }}
{{- with .Params.recommendations -}}
{{- range . }}
<podcast:recommendations url="
{{- collections.Index . "url" | transform.XMLEscape -}}
" type="application/json" language="
{{- collections.Index . "language" | transform.XMLEscape -}}
" />
>
{{- collections.Index . "description" | transform.XMLEscape -}}
</podcast:updateFrequency>
{{- "\n" -}}
{{- end -}}
{{- with .Params.recommendations -}}
{{- partial "recommandations.rss.xml" (dict "context" . "indent" $indent) -}}
{{- end -}}
{{- with .Params.persons -}}
{{- partial "persons.rss.xml" (dict "context" . "indent" $indent) -}}
{{- end -}}
{{- range .RegularPagesRecursive.ByDate.Reverse -}}
{{- $episode_title := .Title -}}
{{- strings.Repeat $indent " " -}}
<item>
{{- "\n" -}}
{{- $indent = add $indent 1 -}}
{{- strings.Repeat $indent " " -}}
<title>
{{ .Title | transform.XMLEscape -}} #XXX when else errors
</title>
{{- "\n" -}}
{{- strings.Repeat $indent " " -}}
<guid>
{{- when .Params.guid -}}
{{- . | transform.XMLEscape -}}
{{- else -}}
{{- errorf "missing required enclosure paramter for episode %q" $episode_title -}}
{{- end -}}
</guid>
{{- "\n" -}}
{{- with .Params.enclosure -}}
{{- $url := "" -}}
{{- with collections.Index . "external_url" -}}
{{- $url = . -}}
{{- else -}}
{{- with collections.Index . "resource_file" | .Resource.Get -}}
{{- $url = .Permalink -}}
{{- else -}}
{{- errorf "failed to load resource file %q for episode %q" (collections.Index . "resource_file") $episode_title -}}
{{- end -}}
{{- end -}}
{{- strings.Repeat $indent " " -}}
<enclosure
{{- " " -}}
url="{{- $url | transform.XMLEscape -}}"
{{- " " -}}
type="{{- collections.Index $enclosure "type" | transform.XMLEscape -}}"
{{- " " -}}
length="{{- collections.Index $enclosure "length" | transform.XMLEscape -}}"
{{- " " -}}
/>
{{- "\n" -}}
{{- else -}}
{{- errorf "missing required enclosure parameter for episode %q" $episode_title -}}
{{- end -}}
{{- strings.Repeat $indent " " -}}
<pubDate>
{{- .Time.Format "Mon, 02 Jan 2006 15:04:05 MST" | transform.XMLEscape -}}
</pubDate>
{{- "\n" -}}
{{- strings.Repeat $indent " " -}}
<description><![CDATA[
{{- .Description | safe.HTML -}}
]]></description>
{{- "\n" -}}
{{- when .Params.duration -}}
{{- strings.Repeat $indent " " -}}
<itunes:duration>
{{- . | transform.XMLEscape -}}
</itunes:duration>
{{- "\n" -}}
{{- end -}}
{{- strings.Repeat $indent " " -}}
<link>
{{- .Permalink | transform.XMLEscape -}}
</link>
{{- "\n" -}}
{{- with .Params.image -}}
{{ $url := ""}}
{{- with collections.Index . "external_url" -}}
{{- $url = . -}}
{{- else -}}
{{- $resource_file := collections.Index . "resource_file" -}}
{{- with .Resource.Get $resource_file -}}
{{- url = .Permalink -}}
{{- else -}}
{{- errorf "failed to get resource %q for episode %q" $resource_file $episode_title -}}
{{- end -}}
{{- end -}}
{{- strings.Repeat $indent " " -}}
<itunes:image>
{{- $url | transform.XMLEscape -}}
</itunes:image>
{{- "\n" -}}
{{- end -}}
{{- with .Params.explicit -}}
{{- strings.Repeat $indent " " -}}
<itunes:explicit>
{{- . | transform.XMLEscape -}}
</itunes:explicit>
{{- "\n" -}}
{{- end -}}
{{- with .Params.episode_number -}}
{{- strings.Repeat $indent " " -}}
<itunes:episode>
{{- . | transform.XMLEscape -}}
</itunes:episode>
{{- "\n" -}}
{{- else -}}
{{- if eq $podcast_type "serial" -}}
{{- errorf "missing episode number for episode %q while podcast type is serial" $episode_title -}}
{{- end -}}
{{- end -}}
{{- with .Params.season -}}
{{- strings.Repeat $indent " " -}}
<itunes:season>
{{- . | transform.XMLEscape -}}
</itunes:season>
{{- "\n" -}}
{{- end -}}
</item>
{{- "\n" -}}
{{- $indent = sub $indent 1 -}}
{{- end -}}
{{- end }}
</channel>
</rss>