Is it possible to make use of images placed in src/routes/<subfolder>/? #3641
-
TL;DR: From what I can tell, images in subfolders are not included when the routes are generated. Is it possible to generate a list (array or object) of images in a subfolder in I made a classic blog structure to get a feel for how Svelte (and Vite) works ( When I try to hit the image path directly, it does not exist (i.e. I'm new to Svelte (and pretty fresh to JavaScript), so forgive my ignorance! Having used Hugo, I just assumed images in a folder would be made available, as is the Hugo convention. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You may check how it's done here - https://github.com/MailCheck-co/mailcheck.site/tree/master/src/routes/blog/does-buying-email-lists-still-work |
Beta Was this translation helpful? Give feedback.
-
SvelteKit only has two types of route, pages which are defined by To answer your question, there are 2 ways to go about this. If you're looking to generate the images in relation to your path, then you'll need to create an endpoint file that has the image extension as the suffix and returns the image blob as the body, ex. -> The other, more straightforward way, would be if you already have the image file and wanted to serve them as is. In this case, you'll put them under |
Beta Was this translation helpful? Give feedback.
SvelteKit only has two types of route, pages which are defined by
.svelte
files, and endpoints which are defined by either.js
or.ts
files, see https://kit.svelte.dev/docs/routing. For static files that are served as-is, you're looking for thekit.files.assets
option, which defaults tostatic
directory, see https://kit.svelte.dev/docs/configuration#files and the demo app example.To answer your question, there are 2 ways to go about this. If you're looking to generate the images in relation to your path, then you'll need to create an endpoint file that has the image extension as the suffix and returns the image blob as the body, ex. ->
<app>/src/routes/blog/[slug]/an-image.jpg.ts
.The ot…