mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-12 22:14:08 +00:00
feat: add Audio shortcode
This commit is contained in:
1 parent
4afdb4deba
commit
ca4f7b07ef
1 file changed
+25
@@ -0,0 +1,25 @@
|
||||
{{/* Enable audio to be loaded from local page dir or media library at `static/media/`. */}}
|
||||
{{/* Supports primarily MP3 and MP4. */}}
|
||||
|
||||
{{ $path := "" }}
|
||||
{{ $root_dir := "" }}
|
||||
{{ if .Get "library" }}
|
||||
{{ $path = "media/" }}
|
||||
{{ $root_dir = "static/" }}
|
||||
{{ end }}
|
||||
|
||||
{{ $audio := printf "%s%s" $path (.Get "src") }}
|
||||
{{ $audio_type := strings.TrimPrefix "." (path.Ext (.Get "src")) | lower }}
|
||||
|
||||
{{/* Set MP3 mime type to mpeg. */}}
|
||||
{{ $audio_type = replace $audio_type "mp3" "mpeg" }}
|
||||
|
||||
{{ if .Get "library" }}
|
||||
{{ $audio = $audio | relURL }}
|
||||
{{ end }}
|
||||
|
||||
{{ with $audio }}
|
||||
<audio controls>
|
||||
<source src="{{ . }}" type="audio/{{$audio_type}}">
|
||||
</audio>
|
||||
{{ end }}
|
||||
Reference in new issue
Block a user