sveltia / sveltia-cms

Alternative to Netlify/Decap CMS. Fast, lightweight, Git-based headless CMS. Modern UX, first-class i18n support, open source & free. Made with Svelte.
MIT License
863 stars 43 forks source link

Support for Dynamic Media Folder Paths per Post #74

Closed deployn closed 10 months ago

deployn commented 10 months ago

Hello,

I'm currently seeking a way to configure individual media folders for each post. In Netlify CMS, you can achieve this by setting the media_folder and public_folder paths dynamically based on the slug like so:

media_folder: '{{slug}}'
public_folder: '{{slug}}'

However, this approach doesn't seem to work in Sveltia. When I try to set the path to /src/content/blog/{{slug}}, the directory is incorrectly created with the literal name "{{slug}}" rather than substituting the actual post slug.

Additionally, I need to maintain locale-specific directories within the blog folder, like this:

blog
|
├── en
│   └── something.md
├── de
│   └── something.md
└── something
    └── image.png

Is there currently a way to have a separate directory for each post's media while also keeping the locale directories intact? Any guidance or workaround would be greatly appreciated.

kyoshino commented 10 months ago

Assuming you’re using Folder Collections Media and Public Folder... When I see the Sveltia code, {{slug}} seems already supported. I’ll figure out why it’s not working.

And okay, you use the i18n support. I actually saw you posted a comment on https://github.com/decaporg/decap-cms/issues/4781 and realized that Sveltia probably has the same issue here even though the codebase is totally different. I’m happy to fix it.

deployn commented 10 months ago

Thanks for the reply. I'll try again with the slug directory. If you say it's supported, I'm sure the problem is on my end.

Edit: You were right, something was wrong with my installation. I am now able to generate the desired structure. The only problem left is relative location of the asset folder (../../something/image.png instead of image.png)

kyoshino commented 10 months ago

The fix is live! https://github.com/sveltia/sveltia-cms/releases/tag/v0.8.5