Skip to content

Commit 230075d

Browse files
authored
feat: add basic audio shortcode (#969)
1 parent f9ff25f commit 230075d

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Audio
3+
resources:
4+
- name: risen
5+
src: "risen.mp3"
6+
title: Risen
7+
params:
8+
credits: "[Sascha Ende on filmmusic.io](https://filmmusic.io/en/song/12856-risen)"
9+
---
10+
11+
The audio shortcode allows you to embed audio files.
12+
13+
## Usage
14+
15+
Define your resources in the page front matter, custom parameter `params.credits` is optional.
16+
17+
<!-- spellchecker-disable -->
18+
19+
```md
20+
---
21+
resources:
22+
- name: risen
23+
src: "risen.mp3"
24+
title: Risen
25+
params:
26+
credits: "[Sascha Ende on filmmusic.io](https://filmmusic.io/en/song/12856-risen)"
27+
---
28+
29+
{{</* audio name="risen" */>}}
30+
```
31+
32+
### Attributes
33+
34+
<!-- prettier-ignore-start -->
35+
<!-- spellchecker-disable -->
36+
{{< propertylist name=shortcode-audio sort=name order=asc >}}
37+
<!-- spellchecker-enable -->
38+
<!-- prettier-ignore-end -->
39+
40+
<!-- spellchecker-enable -->
41+
42+
## Example
43+
44+
<!-- spellchecker-disable -->
45+
46+
{{< audio name="risen" >}}
47+
48+
<!-- spellchecker-enable -->
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
properties:
3+
- name: name
4+
type: string
5+
description: Name of the audio resource defined in page front matter.
6+
required: true

layouts/shortcodes/audio.html

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{- $source := ($.Page.Resources.ByType "audio").GetMatch (printf "%s" (.Get "name")) }}
2+
{{- $customAlt := .Get "alt" }}
3+
4+
5+
{{- with $source }}
6+
{{- $caption := default .Title $customAlt }}
7+
8+
<div class="flex justify-center">
9+
<figure class="gdoc-markdown__figure">
10+
<audio controls class="player" preload="auto">
11+
<source src="{{ .Permalink }}" type="audio/mpeg">
12+
</audio>
13+
{{- with $caption }}
14+
<figcaption>
15+
{{ . }}
16+
{{- with $source.Params.credits }}
17+
{{ printf " (%s)" . | $.Page.RenderString }}
18+
{{- end }}
19+
</figcaption>
20+
{{- end }}
21+
</figure>
22+
</div>
23+
{{- end }}

src/sass/_markdown.scss

+10-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@
100100
max-width: 100%;
101101
height: auto;
102102
}
103+
104+
&:has(audio) {
105+
width: 100%;
106+
107+
audio {
108+
width: 100%;
109+
}
110+
}
103111
}
104112

105113
img {
@@ -109,7 +117,8 @@
109117

110118
blockquote {
111119
margin: defaults.$padding-16 0;
112-
padding: defaults.$padding-8 defaults.$padding-16 defaults.$padding-8 (defaults.$padding-16 - defaults.$padding-4); //to keep total left space 16dp
120+
padding: defaults.$padding-8 defaults.$padding-16 defaults.$padding-8
121+
(defaults.$padding-16 - defaults.$padding-4); //to keep total left space 16dp
113122

114123
border-left: defaults.$border-4 solid var(--accent-color);
115124
border-radius: defaults.$border-radius;

0 commit comments

Comments
 (0)