add filepath shortcode and reorganize shortcodes
This commit is contained in:
27
layouts/shortcodes/embed/audio.html
Normal file
27
layouts/shortcodes/embed/audio.html
Normal file
@ -0,0 +1,27 @@
|
||||
{{ $src := .Get "src" | strings.TrimSpace }}
|
||||
{{ $title := .Get "title" | strings.TrimSpace }}
|
||||
{{ $types := split (.Get "types" | default "") "|" }}
|
||||
|
||||
{{ if not (strings.Contains $src "://") }}
|
||||
{{ $src = relURL $src }}
|
||||
{{ end }}
|
||||
|
||||
<p>
|
||||
<audio class="embed-audio" controls>
|
||||
{{ $extension := path.Ext $src | strings.TrimPrefix "." }}
|
||||
{{ $types = $types | append $extension }}
|
||||
{{ $filepath := strings.TrimSuffix $extension $src }}
|
||||
|
||||
{{ range $types }}
|
||||
{{ $type := . }}
|
||||
{{ $src := print $filepath $type }}
|
||||
<source src="{{ $src }}" type="audio/{{ $type }}">
|
||||
{{ end }}
|
||||
|
||||
Your browser does not support the audio tag. Here is a
|
||||
<a href="{{ $src }}">link to the audio file</a> instead.
|
||||
</audio>
|
||||
{{ with $title }}
|
||||
<em>{{ . }}</em>
|
||||
{{ end }}
|
||||
</p>
|
9
layouts/shortcodes/embed/bilibili.html
Normal file
9
layouts/shortcodes/embed/bilibili.html
Normal file
@ -0,0 +1,9 @@
|
||||
<iframe
|
||||
class="embed-video"
|
||||
loading="lazy"
|
||||
src="https://player.bilibili.com/player.html?bvid={{ .Get "id" }}"
|
||||
scrolling="no"
|
||||
frameborder="0"
|
||||
framespacing="0"
|
||||
allowfullscreen="true"
|
||||
></iframe>
|
45
layouts/shortcodes/embed/video.html
Normal file
45
layouts/shortcodes/embed/video.html
Normal file
@ -0,0 +1,45 @@
|
||||
{{- $src := .Get "src" -}}
|
||||
{{- $title := .Get "title" -}}
|
||||
{{- $poster := .Get "poster" -}}
|
||||
{{- $types := split (.Get "types" | default "") "|" -}}
|
||||
|
||||
{{- /* Process video URL */ -}}
|
||||
{{- if not (strings.Contains $src "://") -}}
|
||||
{{- $src = relURL $src -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Process poster URL */ -}}
|
||||
{{- $posterAttr := "" -}}
|
||||
{{- if $poster -}}
|
||||
{{- if not (strings.Contains $poster "://") -}}
|
||||
{{- $poster = relURL $poster -}}
|
||||
{{- end -}}
|
||||
{{- $posterAttr = printf `poster="%s"` $poster -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Build attributes */ -}}
|
||||
{{- $attributes := slice "controls" -}}
|
||||
{{- if .Get "autoplay" -}}{{- $attributes = $attributes | append "autoplay" -}}{{- end -}}
|
||||
{{- if .Get "loop" -}}{{- $attributes = $attributes | append "loop" -}}{{- end -}}
|
||||
{{- if .Get "muted" -}}{{- $attributes = $attributes | append "muted" -}}{{- end -}}
|
||||
{{- $attributes = delimit $attributes " " -}}
|
||||
|
||||
<div class="video-container">
|
||||
<video class="embed-video file" {{ $posterAttr | safeHTMLAttr }} {{ $attributes | safeHTMLAttr }}>
|
||||
{{- $extension := path.Ext $src | strings.TrimPrefix "." -}}
|
||||
{{- $types = $types | append $extension | uniq -}}
|
||||
{{- $filepath := strings.TrimSuffix (printf ".%s" $extension) $src -}}
|
||||
|
||||
{{- range $types -}}
|
||||
{{- $type := . -}}
|
||||
{{- $src := printf "%s.%s" $filepath $type -}}
|
||||
<source src="{{ $src }}" type="video/{{ $type }}">
|
||||
{{- end -}}
|
||||
|
||||
Your browser doesn't support the video tag. Here's a
|
||||
<a href="{{ $src }}">link to the video file</a> instead.
|
||||
</video>
|
||||
{{- if $title -}}
|
||||
<em>{{ $title }}</em>
|
||||
{{- end -}}
|
||||
</div>
|
9
layouts/shortcodes/embed/youtube.html
Normal file
9
layouts/shortcodes/embed/youtube.html
Normal file
@ -0,0 +1,9 @@
|
||||
<iframe
|
||||
class="embed-video"
|
||||
loading="lazy"
|
||||
src="https://www.youtube.com/embed/{{ .Get "id" }}"
|
||||
title="YouTube video player"
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen
|
||||
></iframe>
|
Reference in New Issue
Block a user