# ------------------------------------------------------------------------------ # ~/_plugins/asciidoctor-extensions/video-block.rb # Asciidoctor extension for local HTML5 Video # # Product/Info: # https://jekyll.one # # Copyright (C) 2023, 2024 Juergen Adams # # J1 Template is licensed under the MIT License. # See: https://github.com/jekyll-one-org/j1-template/blob/main/LICENSE # ------------------------------------------------------------------------------ require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' include Asciidoctor # ------------------------------------------------------------------------------ # A block macro that embeds a local video using VideoJS into the output document # # Usage: # # .Title # video::video_path[start="hh:mm:ss" poster="full_image_path" theme="vjs_theme_name" zoom="true|false" role="CSS classes"] # # Example: # # .MP4 Video, Rolling Wild # videojs::/assets/video/gallery/html5/video2.mp4[start="00:00:50" poster="/assets/video/gallery/video1-poster.jpg" role="mt-4 mb-5"] # # ------------------------------------------------------------------------------ # See: # https://www.tutorialspoint.com/creating-a-responsive-video-player-using-video-js # ------------------------------------------------------------------------------ Asciidoctor::Extensions.register do class VideoJSBlockMacro < Extensions::BlockMacroProcessor use_dsl named :videojs name_positional_attributes 'caption', 'start', 'poster', 'theme', 'zoom', 'role' default_attrs 'caption' => 'true', 'start' => '00:00:00', 'poster' => '/assets/video/gallery/videojs-poster.png', 'theme' => 'uno', 'zoom' => false, 'role' => 'mt-3 mb-3' def process parent, target, attributes # ======================================================================== # load VideoJS configuration data (as NOT available in the website) # ------------------------------------------------------------------------ # current_path = File.expand_path(Dir.getwd) default_config_path = File.join(current_path, '/_data/modules/defaults') user_config_path = File.join(current_path, '/_data/modules') videojs_config_file_name = 'videojs.yml' videojs_default_config_file = File.join(default_config_path, videojs_config_file_name) videojs_user_config_file = File.join(user_config_path, videojs_config_file_name) videojsDefaultSettings = YAML::load(File.open(videojs_default_config_file)) videojsUserSettings = YAML::load(File.open(videojs_user_config_file)) videojsDefaultSettingsJson = videojsDefaultSettings.to_json; videojsUserSettingsJson = videojsUserSettings.to_json; # ======================================================================== # set plugin specific data # ------------------------------------------------------------------------ chars = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map(&:to_a).flatten video_id = (0...11).map { chars[rand(chars.length)] }.join title_html = (attributes.has_key? 'title') ? %(
#{attributes['title']}
\n) : nil poster_image = (poster = attributes['poster']) ? %(#{poster}) : nil theme_name = (theme = attributes['theme']) ? %(#{theme}) : nil caption_enabled = (caption = attributes['caption']) ? true : false html = %(
#{title_html}
) create_pass_block parent, html, attributes, subs: nil end end block_macro VideoJSBlockMacro end