When genrating some static pages with kirby, we’d like to have the assets linked to the folder they are in rather than linked to the media folder. To do that we used the example of the ‘Assets in Content’ plugin, a summary of the index.php is below:
use Kirby\Cms\App as Kirby;
Kirby::plugin(‘name/assets-in-content', [
'components' => [
'file::url' => function (Kirby $kirby, $file) {
return $kirby->url() . '/content/' . $file->parent()->diruri() . '/' . $file->filename();
},
]
]);
This gives a link to the asset something like this: https://domain.net/content/1_books/20210725_book-name/book.epub
The question is, is it possible to get a url more like the actual page url, like the one shown below: https://domain.net/books/book-name/book.epub
Many thanks texnixe, that is brilliant. Static assets are pathed correctly, but images still seem to link to media? I presume there is a reason for this?