ixti/jekyll-assets

View on GitHub
lib/jekyll/assets/plugins/html/defaults/audio.rb

Summary

Maintainability
A
2 hrs
Test Coverage
# Frozen-string-literal: true
# Copyright: 2012 - 2020 - ISC License
# Author: Jordon Bedwell
# Encoding: utf-8

module Jekyll
  module Assets
    class Default
      class Audio < Default
        content_types %r!^audio/[a-zA-Z0-9\-_]+$!
        internal!

        # --
        def set_src
          dpath = asset.digest_path
          return args[:src] = asset.url if asset.is_a?(Url)
          return args[:src] = env.prefix_url(dpath) unless args[:inline]
          # This is insanity, but who am I to judge you, and what you do.
          args[:src] = asset.data_uri
        end

        # --
        def set_controls
          return if args.key?(:controls)

          args[:controls] = true
          unless args.key?(:controlsList) || args.key?(:controlslist)
            args[:controlList] = "nodownload"
          end
        end

        # --
        def set_integrity
          return unless integrity?

          args[:integrity] = asset.integrity
          unless args.key?(:crossorigin)
            args[:crossorigin] = "anonymous"
          end
        end

        # --
        def integrity?
          config[:integrity] && !asset.is_a?(Url) &&
            !args.key?(:integrity)
        end
      end
    end
  end
end

# --
Jekyll::Assets::Hook.register :config, :before_merge do |c|
  c.deep_merge!({
    defaults: {
      audio: {
        integrity: Jekyll.production?,
      },
    },
  })
end