Class: Jekyll::MuxTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll/mux_tag.rb

Constant Summary collapse

EMBED_BASE =
"https://player.mux.com/"
VALID_PARAMS =

Supported query parameters for the Mux iframe embed player. These mirror the Mux Player web component attributes as URL query params.

%w[
  accent-color autoplay loop muted playsinline preload
  metadata-video-id metadata-video-title metadata-viewer-user-id
  metadata-player-name metadata-page-type metadata-sub-property-id
  stream-type start-time
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ MuxTag

Returns a new instance of MuxTag.



19
20
21
22
23
24
# File 'lib/jekyll/mux_tag.rb', line 19

def initialize(tag_name, markup, tokens)
  super
  parts = markup.strip.split(/\s+/, 2)
  @playback_id = parts[0]
  @params = parse_params(parts[1] || "")
end

Instance Method Details

#render(_context) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jekyll/mux_tag.rb', line 26

def render(_context)
  raise "Mux tag requires a playback ID" if @playback_id.nil? || @playback_id.strip.empty?

  src = EMBED_BASE + @playback_id
  unless @params.empty?
    src += "?" + @params.map { |k, v| "#{CGI.escape(k)}=#{CGI.escape(v.to_s)}" }.join("&")
  end

  <<~HTML.strip
    <div class="mux-embed" style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;">
      <iframe
        src="#{src}"
        frameborder="0"
        allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture"
        allowfullscreen
        style="position:absolute;top:0;left:0;width:100%;height:100%;"
        loading="lazy">
      </iframe>
    </div>
  HTML
end