feat: add basic audio shortcode (#969)

This commit is contained in:
Robert Kaussow 2025-02-09 22:20:33 +01:00 committed by GitHub
parent f9ff25f6a4
commit 230075d78b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 87 additions and 1 deletions

View File

@ -0,0 +1,48 @@
---
title: Audio
resources:
- name: risen
src: "risen.mp3"
title: Risen
params:
credits: "[Sascha Ende on filmmusic.io](https://filmmusic.io/en/song/12856-risen)"
---
The audio shortcode allows you to embed audio files.
## Usage
Define your resources in the page front matter, custom parameter `params.credits` is optional.
<!-- spellchecker-disable -->
```md
---
resources:
- name: risen
src: "risen.mp3"
title: Risen
params:
credits: "[Sascha Ende on filmmusic.io](https://filmmusic.io/en/song/12856-risen)"
---
{{</* audio name="risen" */>}}
```
### Attributes
<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< propertylist name=shortcode-audio sort=name order=asc >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->
<!-- spellchecker-enable -->
## Example
<!-- spellchecker-disable -->
{{< audio name="risen" >}}
<!-- spellchecker-enable -->

Binary file not shown.

View File

@ -0,0 +1,6 @@
---
properties:
- name: name
type: string
description: Name of the audio resource defined in page front matter.
required: true

View File

@ -0,0 +1,23 @@
{{- $source := ($.Page.Resources.ByType "audio").GetMatch (printf "%s" (.Get "name")) }}
{{- $customAlt := .Get "alt" }}
{{- with $source }}
{{- $caption := default .Title $customAlt }}
<div class="flex justify-center">
<figure class="gdoc-markdown__figure">
<audio controls class="player" preload="auto">
<source src="{{ .Permalink }}" type="audio/mpeg">
</audio>
{{- with $caption }}
<figcaption>
{{ . }}
{{- with $source.Params.credits }}
{{ printf " (%s)" . | $.Page.RenderString }}
{{- end }}
</figcaption>
{{- end }}
</figure>
</div>
{{- end }}

View File

@ -100,6 +100,14 @@
max-width: 100%;
height: auto;
}
&:has(audio) {
width: 100%;
audio {
width: 100%;
}
}
}
img {
@ -109,7 +117,8 @@
blockquote {
margin: defaults.$padding-16 0;
padding: defaults.$padding-8 defaults.$padding-16 defaults.$padding-8 (defaults.$padding-16 - defaults.$padding-4); //to keep total left space 16dp
padding: defaults.$padding-8 defaults.$padding-16 defaults.$padding-8
(defaults.$padding-16 - defaults.$padding-4); //to keep total left space 16dp
border-left: defaults.$border-4 solid var(--accent-color);
border-radius: defaults.$border-radius;