youtube.pugYoutube videos and playlists

View source code on Github

../../../_images/youtube.png

Embed videos

mixin youtube-video(id)
  - if ("alt" in attributes)
    - alt = attributes.alt;
    - delete attributes.alt;
  - else
    - alt = true;
  - if ("autoplay" in attributes)
    - autoplay = attributes.autoplay;
    - delete attributes.autoplay;
  - else
    - autoplay = false;
  - if (autoplay == true)
    - autoplay = 1;
  - else
    - autoplay = 0;
  - src = `https://www.youtube.com/embed/${id}?autoplay=${autoplay}`
  iframe(src=`${src}`
         frameborder="0"
         allow="autoplay;encrypted-media"
         allowfullscreen="true"
         width="560"
         height="315")&attributes(attributes)
    - if (alt)
      | Your browser does not support iframes.
+youtube-video(id)(autoplay=false, width="560", height="315")

Insert a Youtube video iframe given a identificator.

Arguments:
  • id (string) – Video identificator, corresponds to some letters and numbers located at the end of a video url. For example, if a video has the url https://www.youtube.com/watch?v=xK1bZBzowF0, the identificator is xK1bZBzowF0.
  • autoplay (bool, optional) – If true, video will be inmediatly played after loaded.

Usage

Input

+youtube-video("xK1bZBzowF0")(width="100%")

Output

<iframe width="100%" height="315" src="https://www.youtube.com/embed/xK1bZBzowF0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

Render


Embed playlists

mixin youtube-playlist(id)
  - if ("alt" in attributes)
    - alt = attributes.alt;
    - delete attributes.alt;
  - else
    - alt = true;
  - if ("autoplay" in attributes)
    - autoplay = attributes.autoplay;
    - delete attributes.autoplay;
  - else
    - autoplay = false;
  - if (autoplay == true)
    - autoplay = 1;
  - else
    - autoplay = 0;
  iframe(src=`https://www.youtube.com/embed/videoseries?list=${id}&autoplay=${autoplay}`
         frameborder="0"
         allow="autoplay;encrypted-media"
         allowfullscreen="true"
         width="560"
         height="315")&attributes(attributes)
    - if (alt)
      | Your browser does not support iframes.
+youtube-playlist(id)(width="560", height="315")

Insert a Youtube playlist iframe given an identificator.

Arguments:

Usage

Input

+youtube-playlist("PL9fkilWKH-6BwYucD1jZ8RZS0wHHCik7d")(width="100%")

Output

<iframe width="100%" height="315" src="https://www.youtube.com/embed/videoseries?list=PL9fkilWKH-6BwYucD1jZ8RZS0wHHCik7d" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

Render