mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-20 02:16:40 +00:00
feat: migrate Audio shortcode to use assets/media/
Also support page dir asset or URL
This commit is contained in:
1 parent
bd11c2663b
commit
e14c68cb6d
1 file changed
+21
-18
@@ -1,26 +1,29 @@
|
|||||||
{{/* Enable audio to be loaded from local page dir or media library at `static/media/`. */}}
|
{{/* Audio Shortcode for Wowchemy. */}}
|
||||||
|
{{/* Load audio from page dir falling back to media library at `assets/media/` and then to remote URI. */}}
|
||||||
{{/* Supports primarily MP3 and MP4. */}}
|
{{/* Supports primarily MP3 and MP4. */}}
|
||||||
|
|
||||||
{{ $path := "" }}
|
{{ $destination := .Get "src" }}
|
||||||
{{ $root_dir := "" }}
|
{{ $is_remote := strings.HasPrefix $destination "http" }}
|
||||||
{{ $media_dir := site.Params.media_dir | default "media" }}
|
{{- $asset := "" -}}
|
||||||
{{ if .Get "library" }}
|
{{- if not $is_remote -}}
|
||||||
{{ $path = printf "%s/" $media_dir }}
|
{{- $asset = (.Page.Resources.ByType "image").GetMatch $destination -}}
|
||||||
{{ $root_dir = "static/" }}
|
{{- if not $asset -}}
|
||||||
|
{{- $asset = resources.Get (path.Join "media" $destination) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{ if $asset }}
|
||||||
|
{{ $destination = $asset.RelPermalink }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $destination = $destination | safeURL }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ $audio := printf "%s%s" $path (.Get "src") }}
|
|
||||||
{{ $audio_type := strings.TrimPrefix "." (path.Ext (.Get "src")) | lower }}
|
{{ $audio_type := strings.TrimPrefix "." (path.Ext $destination) | lower }}
|
||||||
|
|
||||||
{{/* Set MP3 mime type to mpeg. */}}
|
{{/* Set MP3 mime type to mpeg. */}}
|
||||||
{{ $audio_type = replace $audio_type "mp3" "mpeg" }}
|
{{ $audio_type = replace $audio_type "mp3" "mpeg" }}
|
||||||
|
|
||||||
{{ if .Get "library" }}
|
<audio controls {{ with (.Get "id") }}id="audio-{{.|anchorize}}"{{end}}>
|
||||||
{{ $audio = $audio | relURL }}
|
<source src="{{$destination}}" type="audio/{{$audio_type}}">
|
||||||
{{ end }}
|
</audio>
|
||||||
|
|
||||||
{{ if $audio }}
|
|
||||||
<audio controls {{ with (.Get "id") }}id="audio-{{.|urlize}}"{{end}}>
|
|
||||||
<source src="{{$audio}}" type="audio/{{$audio_type}}">
|
|
||||||
</audio>
|
|
||||||
{{ end }}
|
|
||||||
Reference in new issue
Block a user