Skip to content

Commit

Permalink
feat: add support for embed video files (cotes2020#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfux authored and gudtldn committed Jul 26, 2024
1 parent 26ff0ea commit a25d361
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
7 changes: 3 additions & 4 deletions _includes/embed/bilibili.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<iframe
class="embed-video bilibili"
class="embed-video"
loading="lazy"
src="https://player.bilibili.com/player.html?bvid={{ include.id }}"
scrolling="no"
border="0"
frameborder="no"
frameborder="0"
framespacing="0"
allowfullscreen="true"
></iframe>
></iframe>
38 changes: 38 additions & 0 deletions _includes/embed/video.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% assign video_url = include.src %}
{% assign poster_url = include.poster %}

{% unless video_url contains '://' %}
{%- capture video_url -%}
{% include img-url.html src=video_url img_path=page.img_path %}
{%- endcapture -%}
{% endunless %}

{% if poster_url %}
{% unless poster_url contains '://' %}
{%- capture poster_url -%}
{% include img-url.html src=poster_url img_path=page.img_path %}
{%- endcapture -%}
{% endunless %}
{% assign poster = 'poster="' | append: poster_url | append: '"' %}
{% endif %}

{% assign attributes = 'controls' %}

{% if include.autoplay %}
{% assign attributes = attributes | append: ' ' | append: 'autoplay' %}
{% endif %}

{% if include.loop %}
{% assign attributes = attributes | append: ' ' | append: 'loop' %}
{% endif %}

{% if include.muted %}
{% assign attributes = attributes | append: ' ' | append: 'muted' %}
{% endif %}

<p>
<video class="embed-video file" src="{{ video_url }}" {{ poster }} {{ attributes }}>
Your browser doesn't support HTML video. Here is a <a href="{{ url }}">link to the video</a> instead.
</video>
<em>{{ include.title }}</em>
</p>
2 changes: 1 addition & 1 deletion _includes/embed/youtube.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<iframe
class="embed-video youtube"
class="embed-video"
loading="lazy"
src="https://www.youtube.com/embed/{{ include.id }}"
title="YouTube video player"
Expand Down
18 changes: 13 additions & 5 deletions _sass/addon/commons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,25 @@ main {
width: 100%;
height: 100%;
margin-bottom: 1rem;
aspect-ratio: 16 / 9;

@extend %rounded;

&.youtube,
&.bilibili {
aspect-ratio: 16 / 9;
}

&.twitch {
aspect-ratio: 310 / 189;
}

&.file {
display: block;
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
margin: auto;
margin-bottom: 0;
}

@extend %img-caption;
}

/* --- buttons --- */
Expand Down

0 comments on commit a25d361

Please sign in to comment.