kirby3-static-site-generator
kirby3-static-site-generator copied to clipboard
Can't use custom assets folder path in static folder
Expected Behavior
Using custom assets
folder path, having the same in project and static
folder.
// index.php
echo new Kirby([
'roots' => [
'assets' => __DIR__ . '/storage/assets',
'media' => __DIR__ . '/storage/media'
],
'urls' => [
'assets' => Url::index() . '/storage/assets',
'media' => Url::index() . '/storage/media'
]
])->render();
I'm expecting generated static
folder to look like:
- static
- storage
- media
- assets
- storage
Current Behavior
assets
folder is generated at static
root:
- static
- assets
- storage
- media
My media folder gets generated where I want, but not assets one.
I'm able to get my assets in both dynamic and static by looking if request matches api/endpoint
when loading one, but would like to be able to do without.
Possible solutions
Didn't find the reason why, didn't really investigate yet but I could. I just wanted to know if this behavior was normal ?
Context
kirby 3.6.5 d4l static site generator: 1.3.0
I have forked the repo and managed to get the behavior I wanted.
When kirby->url->assets()
is set to a deeper path than default (like storage/assets
), assets
gets generated the same way in static folder (static/storage/assets
).
I'm not sure about PR at this point, if someone has set such a custom assets path but still uses static/assets
in static website, it might break their config. Do you think that's a problem ? An additional option could do the job but I think matching project custom folder structure in static site should be default.
By the way amazing plugin, thank you very much and sorry to bother you almost everyday.
Hi @ShallowRed :wave: No problem and thanks for bringing this up. I wouldn't say that the behavior by the plugin is normal, it's just that most people are using the default configuration with /assets
, so this never had a chance to be discovered until now. Even the starterkit does not seem to load its css anymore when specifying a custom urls.assets
:sweat_smile:
Since this change might potentially break the setup of others (even though chances are slim), I'll see if I can incorporate your approach from the fork into something that's backwards-compatible at the same time. As you have already discovered, the issue was that media/pages' file/folder structure is generated from their url, while assets are simply copied over as a folder. I'll see if there's perhaps also the option to invoke file::version
or maybe a js
and css
component when dealing with assets, so they are properly registered and copied, which would then also skip copying assets that are not even in use (but then again that would break things for folks using none of kirby's url helpers for their assets :thinking: I'll come up with something later this week).
Oh you're right about kirby not loading assets in subfolder. I forgot about this but I wrapped assets call in a function that specifies $kirby->url('assets')
before calling css(), js() etc. I find it weird, I might ask directly onto kirby's repo.
The motivation behind this is that I bundle my assets with webpack so I never interact directly with the assets
folder, and I like to keep such folders (accounts, media, cache, sessions
) away from files I actually edit, I find it easier to navigate in my editor tree view.