Skip to content

Comments

Add support for audio files#674

Open
eulersson wants to merge 5 commits intooleeskild:mainfrom
eulersson:main
Open

Add support for audio files#674
eulersson wants to merge 5 commits intooleeskild:mainfrom
eulersson:main

Conversation

@eulersson
Copy link

@eulersson eulersson commented Mar 27, 2025

These changes process also audio files. Images then turn into <img> HTML tags and audios into <audio> HTML tags.

It tries to solve #581.

I tested it manually and it works as expected.

However it also needs changes done in .eleventy.js so it knows how to process the audio files, so this is done into another PR: oleeskild/digitalgarden#306

@oleeskild
Copy link
Owner

wow, thanks! Cool feature. I'll need some time to review it. Hopefully I'll get around to it today

/!\[\[(.*?)(\.(png|jpg|jpeg|gif|webp))\|(.*?)\]\]|!\[\[(.*?)(\.(png|jpg|jpeg|gif|webp))\]\]/g;
const transcludedImageMatches = text.match(transcludedImageRegex);
const transcludedMediaItemRegex =
/!\[\[(.*?)(\.(png|jpg|jpeg|gif|webp|mp3|wav|ogg|m4a))\|(.*?)\]\]|!\[\[(.*?)(\.(png|jpg|jpeg|gif|webp|mp3))\]\]/g;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fishy. The regex looks for mp3|wav|ogg|m4a in the first part, but only mp3 in the second part.
Also the code below always uses
const isAudio = linkedFile.extension === "mp3";
(i.e. only checks for mp3 files)
Except when deleting, where it checks for multiple file extensions again.

I feel like it would be a better idea to split image and audio file handling into separate code paths (using a distinct regex for each) and to avoid the isAudio checks down the line. Checking for specific file extensions at multiple points is asking for trouble when the set of file extensions changes at some point.
Maybe it's possible to attach kind of a "tag" to the Asset object denoting which type of asset it is? Second best would be having an isAudio function which checks for the correct extensions.

@foxblock
Copy link

Thanks for you work. I had a quick look at it and left a comment on a part that caught my eye.

I am interested to get video embeds working (#80) and this seems like a good starting point to piggy back off of.

@eulersson
Copy link
Author

Thanks for the feedback! I'm putting my hands on it again.

@eulersson
Copy link
Author

eulersson commented Aug 4, 2025

Still pending TODOs:

  • Fix: single publish collects and publishes but multi publish doesn't
  • Fix: eleventy.js should without alt, as !()[audio.mp3] and transform it into <audio ... HTML tags properly, now it only does it if in the form of ![hello](/path/to/hello.mp3), but since audios have no alt it doesn't make sense to support this form.

@eulersson
Copy link
Author

@oleeskild @foxblock ready to review again :)

@dzxpert
Copy link

dzxpert commented Jan 26, 2026

interesting feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants