├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── jekyll-youtube.gemspec └── lib ├── jekyll-youtube.rb └── jekyll-youtube └── version.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | .DS_Store 11 | *.gem -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in jekyllcontentful.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dommmel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Youtube 2 | 3 | This Jekyll pluging provides a tag that takes a Youtube URL and generates a (responsive) html snippet to embed the video into your site. 4 | 5 | ## Installation 6 | 7 | Add this line to your Gemfile: 8 | 9 | ```ruby 10 | group :jekyll_plugins do 11 | gem "jekyll-youtube" 12 | end 13 | ``` 14 | 15 | And then execute: 16 | 17 | $ bundle 18 | 19 | Alternatively install the gem yourself as: 20 | 21 | $ gem install jekyll-youtube 22 | 23 | and put this in your ``_config.yml`` 24 | 25 | ```yaml 26 | plugins: [jekyll-youtube] 27 | # This will require each of these gems automatically. 28 | ``` 29 | 30 | ## Usage 31 | 32 | ``` 33 | {% youtube "https://www.youtube.com/watch?v=ho8-vK0L1_8" %} 34 | ``` 35 | or using variables/front matter 36 | 37 | ``` 38 | {% youtube page.youtubeurl %} 39 | ``` 40 | 41 | ## Result 42 | 43 | By default the plugin will output the following code 44 | 45 | 46 | ```markup 47 | 65 |
68 | ``` 69 | 70 | You can specify your own snippet by creating a partial ``_includes/youtube.html``. Inside that partial the Youtube ID is available as ``{{ youtube_id }}``. 71 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /jekyll-youtube.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'jekyll-youtube/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "jekyll-youtube" 8 | spec.version = Jekyll::Youtube::VERSION 9 | spec.authors = ["Dommmel"] 10 | spec.email = ["dommmel@gmail.com"] 11 | 12 | spec.summary = %q{jekyll plugin to generate html snippets for embedding Youtube videos} 13 | spec.description = %q{jekyll plugin to generate html snippets for embedding Youtube videos} 14 | spec.homepage = "https://github.com/dommmel/jekyll-youtube" 15 | spec.license = "MIT" 16 | 17 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_dependency 'jekyll' 21 | spec.add_development_dependency "bundler", "~> 1.10" 22 | spec.add_development_dependency "rake", "~> 10.0" 23 | end 24 | -------------------------------------------------------------------------------- /lib/jekyll-youtube.rb: -------------------------------------------------------------------------------- 1 | require "jekyll" 2 | require "jekyll-youtube/version" 3 | class YouTubeEmbed < Liquid::Tag 4 | 5 | def initialize(tagName, content, tokens) 6 | super 7 | @content = content 8 | end 9 | 10 | def render(context) 11 | youtube_url = "#{context[@content.strip]}" 12 | if youtube_url[/youtu\.be\/([^\?]*)/] 13 | @youtube_id = $1 14 | else 15 | # Regex from # http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/4811367#4811367 16 | youtube_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/] 17 | @youtube_id = $5 18 | end 19 | 20 | tmpl_path = File.join Dir.pwd, "_includes", "youtube.html" 21 | if File.exist?(tmpl_path) 22 | tmpl = File.read tmpl_path 23 | site = context.registers[:site] 24 | tmpl = (Liquid::Template.parse tmpl).render site.site_payload.merge!({"youtube_id" => @youtube_id}) 25 | else 26 | %Q{ } 27 | end 28 | end 29 | 30 | Liquid::Template.register_tag "youtube", self 31 | end -------------------------------------------------------------------------------- /lib/jekyll-youtube/version.rb: -------------------------------------------------------------------------------- 1 | module Jekyll 2 | module Youtube 3 | VERSION = "1.0.0" 4 | end 5 | end 6 | --------------------------------------------------------------------------------