Class: Jekyll::PodlovePlayerTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
OctopodFilters
Defined in:
lib/jekyll/podlove_player_tag.rb

Constant Summary

Constants included from OctopodFilters

OctopodFilters::JSON_ENTITIES

Instance Method Summary collapse

Methods included from OctopodFilters

#audio, #audio_type, #cdata_escape, #disqus_config, #download_url_with_fallback, #episode_feeds, #episode_feeds_html, #episode_feeds_rss, #expand_urls, #fediverse_handle, #file_size, #host_from_url, #image_with_fallback, #in_megabytes, #j, #mime_type, #navbar_item, #navigation_list, #navigation_list_item, #otherwise, #remove_script_and_audio, #sha1, #size_by_format, #slug, #split_chapter, #string_of_duration, #string_of_size, #time_to_rssschema, #version_string

Instance Method Details

#playerbaseconfig(context) ⇒ Object



46
47
48
49
# File 'lib/jekyll/podlove_player_tag.rb', line 46

def playerbaseconfig(context)
  config = context.registers[:site].config
  { version: 5, base: "#{config["url"]}/assets/podlove-player/" }.to_json
end

#playerconfig(context) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll/podlove_player_tag.rb', line 8

def playerconfig(context)
  config = context.registers[:site].config
  page = context.registers[:page]

  download_url = download_url_with_fallback(config)
  audio = (page["audio"] || {}).map do |format, filename|
    size = if page["filesize"] && page["filesize"][format]
             size_by_format(page, format)
           else
             file_size(filename)
           end
    { url: download_url + "/" + filename,
      size: size,
      mimeType: mime_type(format),
      title: format }
  end

  # Podlove Web Player v5's default theme has no UI element that displays episode.subtitle
  # anywhere (verified: absent from the compact header, the chapters panel, and at every
  # viewport width tested) even though it's correctly present in the player's own Redux
  # state - a gap in their stock theme, not a data problem on our end. Folding subtitle into
  # the title that *is* displayed is the pragmatic workaround; the plain subtitle field is
  # still sent too, in case a future custom theme (or theirs, if they ever fix it) uses it.
  title = page["subtitle"] ? "#{page["title"]} - #{page["subtitle"]}" : page["title"]

  { version: 5,
    title: title,
    subtitle: page["subtitle"],
    summary: page["summary"],
    poster: config['url'] + "/assets/img/" + (page["image"] || "logo-360x360.png"),
    link: config['url'] + page["url"],
    publicationDate: page["date"].respond_to?(:xmlschema) ? page["date"].xmlschema : page["date"].to_s,
    duration: page["duration"],
    audio: audio,
    chapters: page["chapters"] ? page["chapters"].map { |chapter| split_chapter(chapter) }.compact : nil
  }.to_json
end

#render(context) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jekyll/podlove_player_tag.rb', line 51

def render(context)
  page = context.registers[:page]
  return unless page["audio"]
  config = context.registers[:site].config
  id = "podlove-player-#{page['id'] ? sha1(page['id'], 8) : 'embed'}"
  return <<~HTML
    <div id="#{id}"></div>
    <script src="#{config["url"]}/assets/podlove-player/embed.js"></script>
    <script>
      window.podlovePlayer('##{id}', #{playerconfig(context)}, #{playerbaseconfig(context)});
    </script>
HTML
end