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"> {{- $podcast_type := "" -}}
<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>
{{- /* 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 */ -}} {{- /* 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" -}} {{- if collections.Index .Params.image "external_url" -}}
{{- collections.Index .Params.image "external_url" | transform.XMLEscape -}} {{- collections.Index .Params.image "external_url" | transform.XMLEscape -}}
{{- else if collections.Index .Params.image "resource_file" -}} {{- else if collections.Index .Params.image "resource_file" -}}
{{- with collections.Index .Params.image "resource_file" | .Resources.Get -}} {{- with collections.Index .Params.image "resource_file" | .Resources.Get -}}
{{- .Permalink -}} {{- $image = .Permalink -}}
{{- else -}} {{- else -}}
{{- errorf "failed to fetch resource %q" (collections.Index .Params.image "resource_file") -}} {{- errorf "failed to fetch resource %q" (collections.Index .Params.image "resource_file") -}}
{{- end -}} {{- end -}}
{{- else -}} {{- else -}}
{{- errorf "empty image parameter on the podcast %q definition" .Title -}} {{- errorf "empty image parameter on the podcast %q definition" .Title -}}
{{- end -}} {{- 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: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 */ -}} {{- /* 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 */ -}} {{- /* The following code ensures the attribute is set (Apple requires it) and validates the value against the list of acceptable values */ -}}
{{- with .Params.category }} {{- with .Params.category }}
{{- $category := "" -}}
{{- $categories := resources.Get "categories.json" | transform.Unmarshal -}} {{- $categories := resources.Get "categories.json" | transform.Unmarshal -}}
{{- $categoryFound := 0 -}} {{- $categoryFound := 0 -}}
{{- range ( collections.Index $categories "Categories") -}} {{- range ( collections.Index $categories "Categories") -}}
@ -32,42 +54,88 @@
{{- $categoryFound = 1 -}} {{- $categoryFound = 1 -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- if $categoryFound }} {{- if $categoryFound -}}
<itunes:category>{{ . | transform.XMLEscape }}</itunes:category> {{- strings.Repeat $indent " " -}}
<itunes:category>
{{- . | transform.XMLEscape -}}
</itunes:category>
{{- "\n" -}}
{{- else -}} {{- else -}}
{{- errorf "could not find %q in known categories" . -}} {{- errorf "could not find %q in known categories" . -}}
{{- end -}} {{- end -}}
{{- else -}} {{- else -}}
{{- errorf "missing category definition for podcast %q" .Title -}} {{- errorf "missing category definition for podcast %q" .Title -}}
{{- end }} {{- end -}}
{{- with .Params.website_link }} {{- with .Params.website_link }}
<link>{{ . | transform.XMLEscape }}</link> {{- strings.Repeat $indent " " -}}
{{- end }} <link>
<itunes:explicit>{{ .Params.explicit | transform.XMLEscape }}</itunes:explicit> {{- . | transform.XMLEscape -}}
{{- with .Params.author }} </link>
<itunes:author>{{ . | transform.XMLEscape }}</itunes:author> {{- "\n" -}}
{{- end }} {{- end -}}
{{- with .Params.podcast_type }}
<itunes:type>{{ . | transform.XMLEscape }}</itunes:type> {{- with .Params.author -}}
{{- end }} {{- strings.Repeat $indent " " -}}
{{- if and .Params.author .Params.email }} <itunes:author>
<itunes:owner> {{- . | transform.XMLEscape -}}
<itunes:name>{{ .Params.author | transform.XMLEscape }}</itunes:name> </itunes:author>
<itunes:email>{{ .Params.email | transform.XMLEscape }}</itunes:email> {{- "\n" -}}
</itunes:owner> {{- end -}}
{{- end }}
<podcast:guid>{{ .Params.guid | transform.XMLEscape }}</podcast:guid> {{- with .Params.podcast_type -}}
{{- if and .Params.email .Params.locked }} {{- $podcast_type = . -}}
<podcast:locked owner="{{ .Params.email | transform.XMLEscape }}">{{ .Params.locked | transform.XMLEscape }}</podcast:locked> {{- strings.Repeat $indent " " -}}
{{- end }} <itunes:type>
{{- with .Params.medium }} {{- . | transform.XMLEscape -}}
<podcast:medium>{{ . | transform.XMLEscape }}</podcast:medium> </itunes:type>
{{- end }} {{- "\n" -}}
{{- with .Params.licence }} {{- end -}}
<podcast:licence url="{{ .url | transform.XMLEscape }}">{{ .name | transform.XMLEscape }}</podcast:licence>
{{- end }} {{- if and .Params.author .Params.email -}}
{{- with .Params.images }} {{- strings.Repeat $indent " " -}}
<podcast:images srcset=" <itunes:owner>
{{- "\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>
{{- "\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 -}} {{- $image_url_list := slice -}}
{{- range . -}} {{- range . -}}
{{- $entry := . -}} {{- $entry := . -}}
@ -82,84 +150,229 @@
{{- $attr := printf "%s %sw" $url $width -}} {{- $attr := printf "%s %sw" $url $width -}}
{{- $image_url_list = append $attr $image_url_list -}} {{- $image_url_list = append $attr $image_url_list -}}
{{- end -}} {{- end -}}
{{- delimit $image_url_list "," -}}
"></podcast:images> {{- strings.Repeat $indent " " -}}
{{- end }} <podcast:images srcset="{{- delimit $image_url_list "," -}}" />
{{- "\n" -}}
{{- end -}}
{{- with .Params.funding -}} {{- with .Params.funding -}}
{{- range . }} {{- partial "funding.rss.xml" (dict "context" . "indent" $indent) -}}
<podcast:funding url="{{ .url | transform.XMLEscape }}">{{ .comment | transform.XMLEscape }}</podcast:funding> {{- end -}}
{{- end -}}
{{- end }} {{- with .Params.location -}}
{{- 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> <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 -}} {{- with .Params.trailer -}}
{{- range . -}} {{- range . -}}
{{- $season_attr := "" -}} {{- $season_attr := "" -}}
{{- $url := "" -}}
{{ $url := ""}}
{{- with collections.Index . "resource_file" | $.Resources.Get -}} {{- with collections.Index . "resource_file" | $.Resources.Get -}}
{{- $url = .Permalink -}} {{- $url = .Permalink -}}
{{- else -}} {{- else -}}
{{- $url = collections.Index . "external_url" -}} {{- $url = collections.Index . "external_url" -}}
{{- end -}} {{- end -}}
<podcast:trailer pubdate=" {{- strings.Repeat $indent " " -}}
{{- collections.Index . "pubdate" | transform.XMLEscape -}} <podcast:trailer
" url=" {{- " " -}}
{{- $url -}} pubdate="{{- collections.Index . "pubdate" | transform.XMLEscape -}}"
" length=" {{- " " -}}
{{- collections.Index . "length" | transform.XMLEscape -}} url="{{- $url -}}"
" type="{{- collections.Index . "type" | transform.XMLEscape -}}" {{- " " -}}
{{- if collections.Index . "season" }} season="{{- collections.Index . "season" | transform.XMLEscape -}}" length="{{- collections.Index . "length" | transform.XMLEscape -}}"
{{- " " -}}
type="{{- collections.Index . "type" | transform.XMLEscape -}}"
{{- if collections.Index . "season" -}}
{{- " " -}}
season="{{- collections.Index . "season" | transform.XMLEscape -}}"
{{- end -}} {{- end -}}
>{{- collections.Index . "title" | transform.XMLEscape -}}</podcast:trailer> >
{{- collections.Index . "title" | transform.XMLEscape -}}
</podcast:trailer>
{{- "\n" -}}
{{- end -}} {{- end -}}
{{- end }} {{- end -}}
{{- with .Params.social_interacts }}
{{- range . -}} {{- with .Params.social_interacts -}}
<podcast:socialInteract protocol=" {{- partial "socialInteracts.rss.xml" (dict "context" . "indent" $indent) -}}
{{- collections.Index . "protocol" | transform.XMLEscape -}} {{- end -}}
" uri="
{{- collections.Index . "uri" | transform.XMLEscape -}} {{- with .Params.podroll -}}
" priority=" {{- strings.Repeat $indent " " -}}
{{- collections.Index . "priority" | transform.XMLEscape -}} <podcast:podroll>
" /> {{- range . -}}
{{- end -}} <podcast:remoteItem
{{- end }} {{- " " -}}
{{- with .Params.podroll }} feedGuid="{{- collections.Index . "feed_guid" -}}"
<podcast:podroll> {{- " " -}}
{{- range . }} feedUrl="{{- collections.Index . "feed_url" -}}"
<podcast:remoteItem feedGuid=" {{- " " -}}
{{- collections.Index . "feed_guid" -}} medium="{{- collections.Index . "medium" -}}"
" feedUrl=" {{- " " -}}
{{- collections.Index . "feed_url" -}} title="{{- collections.Index . "title" -}}" />
" medium=" {{- "\n" -}}
{{- collections.Index . "medium" -}} {{- end -}}
" title=" </podcast:podroll>
{{- collections.Index . "title" -}} {{- "\n" -}}
" /> {{- end -}}
{{- end }}
</podcast:podroll> {{- with .Params.update_frequency -}}
{{- end }} {{- strings.Repeat $indent " " -}}
{{- with .Params.update_frequency }} <podcast:updateFrequency
<podcast:updateFrequency {{ if collections.Index . "complete" -}} {{- if collections.Index . "complete" -}}
{{- " " -}}
complete="true" complete="true"
{{- else -}} {{- else -}}
{{- $dtstart := collections.Index . "dtstart" -}} {{- $dtstart := collections.Index . "dtstart" -}}
rrule="{{- collections.Index . "rrule" | transform.XMLEscape -}}" {{ if $dtstart -}} {{- " " -}}
dtstart="{{- $dtstart | transform.XMLEscape -}}" rrule="{{- collections.Index . "rrule" | transform.XMLEscape -}}"
{{- end -}} {{- if $dtstart -}}
{{- end -}} {{- " " -}}
>{{- collections.Index . "description" | transform.XMLEscape -}}</podcast:updateFrequency> dtstart="{{- $dtstart | transform.XMLEscape -}}"
{{- end }} {{- end -}}
{{- end -}}
>
{{- collections.Index . "description" | transform.XMLEscape -}}
</podcast:updateFrequency>
{{- "\n" -}}
{{- end -}}
{{- with .Params.recommendations -}} {{- with .Params.recommendations -}}
{{- range . }} {{- partial "recommandations.rss.xml" (dict "context" . "indent" $indent) -}}
<podcast:recommendations url=" {{- end -}}
{{- collections.Index . "url" | transform.XMLEscape -}}
" type="application/json" language=" {{- with .Params.persons -}}
{{- collections.Index . "language" | transform.XMLEscape -}} {{- partial "persons.rss.xml" (dict "context" . "indent" $indent) -}}
" /> {{- end -}}
{{- end -}}
{{- 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 -}}
</channel> </channel>
</rss> </rss>