feat: add support for embed video files (#1558)
This commit is contained in:
parent
8a1568c27a
commit
9592146ca3
5 changed files with 82 additions and 10 deletions
|
@ -1,10 +1,9 @@
|
||||||
<iframe
|
<iframe
|
||||||
class="embed-video bilibili"
|
class="embed-video"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
src="https://player.bilibili.com/player.html?bvid={{ include.id }}"
|
src="https://player.bilibili.com/player.html?bvid={{ include.id }}"
|
||||||
scrolling="no"
|
scrolling="no"
|
||||||
border="0"
|
frameborder="0"
|
||||||
frameborder="no"
|
|
||||||
framespacing="0"
|
framespacing="0"
|
||||||
allowfullscreen="true"
|
allowfullscreen="true"
|
||||||
></iframe>
|
></iframe>
|
||||||
|
|
38
_includes/embed/video.html
Normal file
38
_includes/embed/video.html
Normal file
|
@ -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>
|
|
@ -1,5 +1,5 @@
|
||||||
<iframe
|
<iframe
|
||||||
class="embed-video youtube"
|
class="embed-video"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
src="https://www.youtube.com/embed/{{ include.id }}"
|
src="https://www.youtube.com/embed/{{ include.id }}"
|
||||||
title="YouTube video player"
|
title="YouTube video player"
|
||||||
|
|
|
@ -427,6 +427,8 @@ Or adding `render_with_liquid: false` (Requires Jekyll 4.0 or higher) to the pos
|
||||||
|
|
||||||
## Videos
|
## Videos
|
||||||
|
|
||||||
|
### Video Sharing Platform
|
||||||
|
|
||||||
You can embed a video with the following syntax:
|
You can embed a video with the following syntax:
|
||||||
|
|
||||||
```liquid
|
```liquid
|
||||||
|
@ -443,6 +445,31 @@ The following table shows how to get the two parameters we need in a given video
|
||||||
| [https://www.**twitch**.tv/videos/**1634779211**](https://www.twitch.tv/videos/1634779211) | `twitch` | `1634779211` |
|
| [https://www.**twitch**.tv/videos/**1634779211**](https://www.twitch.tv/videos/1634779211) | `twitch` | `1634779211` |
|
||||||
| [https://www.**bilibili**.com/video/**BV1Q44y1B7Wf**](https://www.bilibili.com/video/BV1Q44y1B7Wf) | `bilibili` | `BV1Q44y1B7Wf` |
|
| [https://www.**bilibili**.com/video/**BV1Q44y1B7Wf**](https://www.bilibili.com/video/BV1Q44y1B7Wf) | `bilibili` | `BV1Q44y1B7Wf` |
|
||||||
|
|
||||||
|
### Video File
|
||||||
|
|
||||||
|
If you want to embed a video file directly, use the following syntax:
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{% include embed/video.html src='{URL}' %}
|
||||||
|
```
|
||||||
|
|
||||||
|
Where `URL` is an URL to a video file e.g. `/assets/img/sample/video.mp4`.
|
||||||
|
|
||||||
|
You can also specify additional attributes for the embedded video file. Here is a full list of attributes allowed.
|
||||||
|
|
||||||
|
- `poster='/path/to/poster.png'` - poster image for a video that is shown while video is downloading
|
||||||
|
- `title='Text'` - title for a video that appears below the video and looks same as for images
|
||||||
|
- `autoplay=true` - video automatically begins to play back as soon as it can
|
||||||
|
- `loop=true` - automatically seek back to the start upon reaching the end of the video
|
||||||
|
- `muted=true` - audio will be initially silenced
|
||||||
|
|
||||||
|
Consider an example utilizing all of the above:
|
||||||
|
|
||||||
|
```liquid
|
||||||
|
{% include embed/video.html src='video.mp4' poster='poster.png' title='Demo video'
|
||||||
|
autoplay=true loop=true muted=true %}
|
||||||
|
```
|
||||||
|
|
||||||
## Learn More
|
## Learn More
|
||||||
|
|
||||||
For more knowledge about Jekyll posts, visit the [Jekyll Docs: Posts](https://jekyllrb.com/docs/posts/).
|
For more knowledge about Jekyll posts, visit the [Jekyll Docs: Posts](https://jekyllrb.com/docs/posts/).
|
||||||
|
|
|
@ -550,17 +550,25 @@ main {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
aspect-ratio: 16 / 9;
|
||||||
|
|
||||||
@extend %rounded;
|
@extend %rounded;
|
||||||
|
|
||||||
&.youtube,
|
|
||||||
&.bilibili {
|
|
||||||
aspect-ratio: 16 / 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.twitch {
|
&.twitch {
|
||||||
aspect-ratio: 310 / 189;
|
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 --- */
|
/* --- buttons --- */
|
||||||
|
|
Loading…
Reference in a new issue