Hugo generator简单易用,一直让我非常满意,但是当要给blog添加音频或视频文件时,我非常苦恼....
Hugo使用shotcode从YouTube或Vimeo插入视频文件。hexo可以直接使用html代码来添加视频和音频文件,但是hugo并不可以!
因此...我从网上找到了一个别人写的shotcode
在 ~/themes/$your-theme/layouts/shotcodes/audio.html 中添加
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<audio controls
class="audio_controls {{ .Get "class" }}"
{{ with .Get "id" }}id="{{ . }}"{{ end }}
{{ with .Get "preload" }}preload="{{ . }}"{{ else }}preload="metadata"{{ end }}
style="{{ with .Get "style" }}{{ . | safeCSS }}; {{ end }}
{{ with .Get "width" }}width:{{ . }}; {{ end }}
{{ with .Get "height" }}height:{{ . }};{{ end }}"
{{ with .Get "title" }}data-info-title="{{ . }}"{{ end }}
{{ with .Get "attr" }}data-info-attr="{{ . }}"{{ end }}
{{ with .Get "attr_link" }}data-info-attr-link="{{ . }}"{{ end }}
{{ with .Get "year" }}data-info-year="{{ . }}"{{ end }}
{{ with .Get "artist" }}data-info-artist="{{ . }}"{{ end }}
{{ with .Get "album_title" }}data-info-album-title="{{ . }}"{{ end }}
{{ with .Get "album_art" }}data-info-album-art="{{ . }}"{{ end }}
{{ with .Get "label" }}data-info-label="{{ . }}"{{ end }}
>
{{ if .Get "src" }}
<source {{ with .Get "src" }}src="{{ . }}"{{ end }}
{{ with .Get "type" }}type="audio/{{ . }}"{{ end }}>
{{ else if .Get "backup_src" }}
<source src="{{ .Get "backup_src" }}"
{{ with .Get "backup_type" }}type="audio/{{ . }}"{{ end }}
{{ with .Get "backup_codec" }}codecs="{{ . }}"{{ end }}
>
{{ end }}
Your browser does not support the audio element
</audio>
|
这样,在写文章时,就可以使用 audio shotcodes来播放mp3文件了。
1
2
|
前面增加一个“{”
{< audio src="https://your-path-to-music.mp3" >}}
|
下面是个示例
1
2
|
前面增加一个“{”
{< audio src="https://blog.reez.me/audio/test.mp3" >}}
|