#import from public directory with experimental assets and content collections

12 messages · Page 1 of 1 (latest)

wintry girder
#

I was expecting that the config validation would accept the path starting with slash "/astro_island.svg" to be "public/astro_island.svg" but I get an error message with astro dev saying that the path doesn't exist. I found the release notes saying that this change fixed relative imports in front matter, and I confirmed that the relative path to the public directory works fine, but i also get a warning saying the source should be specified from root (last picture). Is this a bug or are frontmatter imports not meant to work directly from public?

Astro

CDN support for assets • image() schema helper API change • Much more!

final lintelBOT
#
No-one around right now?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

worthy island
#

Hey lioumens! From my understanding, the image() property cannot be used with paths to images within public/, nor can it optimize images in public/. You'll need to move these images to your src directory instead

#

cc @lean arch in case there's caveats

wintry girder
#

Thanks Ben, I think about type-checking in content collections as completely separate from the image optimization and how it's loaded in the webpage, is that not correct? For example, the <Image /> component doesn't optimize .svg files, so that's why I have it in public/ and I have a conditional statement depending on the file ending to use a regular <img> tag depending on the filetype. It would be nice if the image type-checking didn't depend on how the picture was rendered, or from where, as long as it's a valid image.

For now, I've moved things to src/assets regardless if it needs optimization or not, and use relative paths in my YAML and that seems to work fine.

lean arch
#

The image() schema does not optimize

#

It just imports the image

worthy island
lean arch
#

Yeah, it's equivalent to doing import image from "/path"

worthy island
#

Right. In that case, I can't think of a good solution if your images could come from public and not-public. Other than moving everything to assets

#

Or having an optional publicUrl property that just maps to z.string() instead (wouldn't be able to refine though)

lean arch
#

I'd honestly just put the .SVGs in src anywhere