This commit is contained in:
Florian Maury 2024-10-23 16:37:24 +02:00
parent bd18ab9792
commit 18df5aeab5
12 changed files with 99 additions and 31 deletions

View file

@ -5,6 +5,12 @@ date: {{ .Date }} # podcast field: pubDate
outputs: outputs:
- html - html
- chapters - chapters
- chapterspodlove
- transcriptsrt
- transcriptwebvtt
- transcripthtml
- transcriptjson
- transcriptpodlove
type: episode type: episode
params: params:
enclosure: enclosure:
@ -58,9 +64,9 @@ params:
# chapters: # podcast field: podcast:chapters # chapters: # podcast field: podcast:chapters
# - start_time: 0.0 # - start_time: 0.0
# title: "" # title: ""
# toc: true # this field needs to be defined and set to true if that chapter must be present in the table of content
# image: "" # image: ""
# url: "" # url: ""
# toc: true
# end_time: 0.0 # end_time: 0.0
# location: # location:
# name: "" # name: ""

View file

@ -1,3 +0,0 @@
baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'

View file

@ -1,6 +1,41 @@
{ {{- $chapters := slice -}}
"version": "1.2.0", {{- with .Params.chapters -}}
"chapters": {{- range . -}}
[ {{- $start_time_value := printf "%.3f" .start_time | cast.ToFloat -}}
] {{- $entry := dict "startTime" $start_time_value "title" .title -}}
} {{- with .image -}}
{{- $entry = collections.Merge $entry (dict "img" .image) -}}
{{- end -}}
{{- with .url -}}
{{- $entry = collections.Merge $entry (dict "url" .url) -}}
{{- end -}}
{{- with .toc -}}
{{- $entry = collections.Merge $entry (dict "toc" .toc) -}}
{{- end -}}
{{- with .end_time -}}
{{- $end_time_value := printf "%.3f" .end_time | cast.ToFloat -}}
{{- $entry = collections.Merge $entry (dict "endTime" $end_time_value) -}}
{{- end -}}
{{- with .location -}}
{{- $name := collections.Index .location "name" -}}
{{- $geo := collections.Index .location "geo" -}}
{{- $entry = collections.Merge $entry (dict "location" (dict "name" $name "geo" $geo)) -}}
{{- end -}}
{{- $chapters = collections.Append $entry $chapters -}}
{{- end -}}
{{- end -}}
{{- $version := "1.2.0" -}}
{{- $document := dict "version" $version "chapters" $chapters "title" .Title "description" .Description -}}
{{- with .Params.author -}}
{{- $document = collections.Merge $document (dict "author" .) -}}
{{- end -}}
{{- $podcast_name := "" -}}
{{- $podcast_page := collections.Where .Ancestors "Type" "podcast" -}}
{{- if eq (len $podcast_page) 1 -}}
{{- $document = collections.Merge $document (dict "podcastName" (collections.Index $podcast_page 0).Title) -}}
{{- end -}}
{{- encoding.Jsonify (dict "noHTMLEscape" true) $document | safe.JS -}}

View file

@ -0,0 +1,18 @@
{{- $chapters := slice -}}
{{- with .Params.chapters -}}
{{- range . -}}
{{ $start_time := collections.Index . "start_time" }}
{{- $start_timecode := partial "ms_to_timecode.tmpl" (dict "start_time" $start_time "long_format" true) -}}
{{- $image := "" -}}
{{- with .image -}}
{{- $image = . -}}
{{- end -}}
{{- $href := "" -}}
{{- with .url -}}
{{- $href = . -}}
{{- end -}}
{{- $entry := dict "start" $start_timecode "title" .title "image" $image "href" $href -}}
{{- $chapters = collections.Append $entry $chapters -}}
{{- end -}}
{{- end -}}
{{- encoding.Jsonify (dict "noHTMLEscape" true) $chapters | safe.JS -}}

View file

@ -0,0 +1 @@
<hr/>

View file

@ -0,0 +1 @@
{"json": true}

View file

@ -0,0 +1 @@
{"pod": "love"}

View file

@ -0,0 +1 @@
bla

View file

@ -0,0 +1 @@
WEBVTT

View file

@ -0,0 +1,22 @@
{{- $start_time := collections.Index . "start_time" -}}
{{- $long_format := collections.Index . "long_format" -}}
{{- $start_time_ms := math.Floor (math.Mul $start_time 1000) -}}
{{- $time_str := "" -}}
{{- $hour_cnt := math.Div $start_time_ms 3600000 | math.Floor | cast.ToInt -}}
{{- $rem := math.Mod $start_time_ms 3600000 -}}
{{- if or $long_format (compare.Gt $hour_cnt 0) -}}
{{- $time_str = printf "%02d:" $hour_cnt -}}
{{- end -}}
{{- $min_cnt := math.Div $rem 60000 | math.Floor | cast.ToInt -}}
{{- $rem = math.Mod $rem 60000 -}}
{{- if or $long_format $time_str (compare.Gt $min_cnt 0) -}}
{{- $time_str = printf "%s%02d:" $time_str $min_cnt -}}
{{- end -}}
{{- $sec_cnt := math.Div $rem 1000 | math.Floor | cast.ToInt -}}
{{- $time_str = printf "%s%02d" $time_str $sec_cnt -}}
{{- $ms_cnt := math.Mod $rem 1000 -}}
{{- if or $long_format (compare.Gt $ms_cnt 0) -}}
{{- $time_str = printf "%s.%03d" $time_str $ms_cnt -}}
{{- end -}}
{{- return $time_str -}}

View file

@ -3,24 +3,7 @@
{{- $start_time := collections.Index $ctx "start_time" -}} {{- $start_time := collections.Index $ctx "start_time" -}}
{{- $title := collections.Index $ctx "title" -}} {{- $title := collections.Index $ctx "title" -}}
{{- $start_time_ms := math.Floor (math.Mul $start_time 1000) -}} {{- $time_str := partial "ms_to_timecode.tmpl" (dict "start_time" $start_time "long_format" false) -}}
{{- $time_str := "" -}}
{{- $hour_cnt := math.Div $start_time_ms 3600000 -}}
{{- $rem := math.Mod $start_time_ms 3600000 -}}
{{- if compare.Gt $hour_cnt 0 -}}
{{- $time_str = printf "%02d:" $hour_cnt -}}
{{- end -}}
{{- $min_cnt := math.Div $rem 60000 -}}
{{- $rem = math.Mod $rem 60000 -}}
{{- if compare.Or $time_str (compare.Gt $min_cnt 0) -}}
{{- $time_str = printf "%s%02d:" $time_str $min_cnt -}}
{{- end -}}
{{- $sec_cnt := math.Div $rem 1000 -}}
{{- $time_str = printf "%s%02d:" $time_str $sec_cnt -}}
{{- $ms_cnt := math.Mod $rem 1000 -}}
{{- if compare.Gt $ms_cnt 0 -}}
{{- $time_str = printf "%s.%03d" $ms_cnt -}}
{{- end -}}
{{- strings.Repeat $indent " " -}} {{- strings.Repeat $indent " " -}}
<psc:chapter start="{{- $time_str -}}" title="{{- $title -}}" /> <psc:chapter start="{{- $time_str -}}" title="{{- $title -}}" />

View file

@ -459,9 +459,11 @@
{{- end -}} {{- end -}}
{{- with .Params.chapters -}} {{- with .Params.chapters -}}
{{- with $episode_page.OutputFormats.Get "chapters" -}}
{{- strings.Repeat $indent " " -}} {{- strings.Repeat $indent " " -}}
<podcast:chapters url="{{ ($episode_page.OutputFormats.Get "chapters").Permalink }}" type="application/json+chapters" /> <podcast:chapters url="{{ .Permalink }}" type="application/json+chapters" />
{{- "\n" -}} {{- "\n" -}}
{{- end -}}
{{- strings.Repeat $indent " " -}} {{- strings.Repeat $indent " " -}}
<psc:chapters version="1.2" xmlns:psc="http://podlove.org/simple-chapters"> <psc:chapters version="1.2" xmlns:psc="http://podlove.org/simple-chapters">
{{- "\n" -}} {{- "\n" -}}