In SvelteKit the blog pages must be in a
blog folder (or
post, or any other name). The post url will look something like:
Instead I prefer a simpler url:
Partly because I write a few posts, partly for personal taste. I know that it is not a widespread practice but mine sine qua non condition to switch from Jekyll to Svelte is the possibility of use the same url structure.
There is another important condition: I want to keep post images in the same folder with the
.md file. I prefer to keep everything together, it makes my life easier when I write.
I had to search a bit, but combining various pieces and trying and trying again I managed to get something working.
Before starting a few links:
- Building a Better Svelte Data Flow: it’s for Sapper but still useful
- Vite — Glob Import
- Sveltekit Markdown Blog
The trick is to “map” all blog posts and keep them as “modules”. Then I use Vite to dynamically import the modules into the blog. To test I don’t create a new repository. I continue modifying the MEMENTO SvelteKit & GitHub Pages: I add a
src/news folder in which to insert the various posts.
I use a structure similar to the one I will need in my blog. So the posts will be divided by year but not by month. Each post will stay in a folder whose first few characters represent the publication date. Inside the folder I will put the images I will need and an
index.md file with the post. I think in the future I will have to add the ability to use markdown files with other names. That's enough for the moment.
Every post will be in a path similar to: