Hi,
I place mp3 files in the content folder. To skip the creation of copies in the media folder I considered the article: Skip Media Folder.
My change was only to substitude the parameter video to audio with:
<?php
// import App class
use Kirby\Cms\App as Kirby;
Kirby::plugin('cookbook/file-component', [
'components' => [
'file::url' => function (Kirby $kirby, $file) {
// serve videos from content folder
if ($file->type() === 'audio') {
return $kirby->url() . '/content/' . $file->parent()->diruri() . '/' . $file->filename();
// while all other files are served from the media folder
} else {
return $file->mediaUrl();
}
},
]
]);
Together with the necessary step to comment out a line in the .htaccess file:
# block all files in the content folder from being accessed directly
# RewriteRule ^content/(.*) index.php [L]
Everthing is fine so far, the URL to my mp3-file is directed to the content folder and not more to the media folder, but nevertheless Kirby creates a copy of the mp3-file into the media folder!
Why?
I just tested it in the starter kit with image files, and didn’t get any copies in the media folder. Did you delete the original copies from the media folder before testing your code?
Yes, I deleted the media folder several times. And I use the actual Kirby version.
I created a screen-movie to explain the Kirby media folder behavior in a better way. The link of this short movie is sent to you via direct message.
What I noticed is that the url to the audio file doesn’t have the content
part in it, so that’s probably the issue here, because some redirect kicks in.
But is not this the standard behavior by Kirby, to hide in the url the content-folder-name and show only the subfolder-structure?
I have the following structure:
content
|-01_podcast
| |-01_episod-01
| |-episode.txt
| |-episode_01.mp3
|-02_blog
From my point of view there is no redirect. The plug-in self create the url to the content folder as awaited and not more to the media folder. The url shows the right path to the mp3-file and I can play the mp3-file as it shown in the video.
For some reason, Kirby still creates a copy of the mp3-file into the media folder!
If we have not a solution I can change the concept and relocate the mp3-files to another folder outside of the content folder. But then I loose the possibility to work with the panel.
This is what my image links in the starterkit look like that do not create a copy in the media folder:
<img src="http://4xz.test/content/1_photography/1_trees/monster-trees-in-the-fog.jpg" alt="Huge trees reaching into the fog">
As you can see in the page tree in the media folder, there are only the job files for thumbs and some thumbs, but no the orignal images themselves (which I’m using here on the home page of the Starterkit for testing).
When I change my code to generate urls like the ones you use:
return $kirby->url() . '/' . $file->parent()->id() . '/' . $file->filename();
Then I also get the image copies in the media folder.
So to me, it looks as if you were exactly NOT using the code you posted in your first post (and which is the one from the cookbook) but a modified version.
What I can write is, that I use exactly the code, what I posted in my first post.
To follow your approach, I installed the starterkit and here are my results:
-
I can confirm your results with images. The plugin let creates ‘only’ work/job files of the images and the url to the original tree-image shows the content folder. Everthing is fine.
-
But I used the same starterkit with the same plug-in code to analyse the mp3-file behavior. Especially to exclude a code problem in my audio environment, at the end to have an indipendend test environment. What I changed was only in the plug-in the relation to audio files instead of images.
a) The URL within the audio-tags shows to the content folder and not to the media folder. But the address has not a content-folder as part of the complete address.
b) And a copy of the mp3-file is created in the media-folder.
My analysis is recorded as a screen-cast that you have the chance to follow my steps and to see the effects.
Thank you very much for your time. I think we have spent too much time for it. To reduce the effort, I will change my concept.