Replies: 2 comments 2 replies
-
+1. However, I'm concerned by one thing: In Vite to get the file path of a file, you can simply import them, right. However, this only works for assets that are part of the So not 100% sure what it'd look like. Maybe it could have a |
Beta Was this translation helpful? Give feedback.
-
I don’t know how we could best support file format assertions. The regular Zod approach with One possibility could be that {
/** Vite-provided URL to this asset */
url: string;
/** File extension or MIME type */
format: string;
} Then it’s easier to refine, e.g. asset().refine(({ format }) => ['mov','mp4'].includes(format)) That does interfere with whatever the An alternative would probably be an API inside the asset({ formats: ['mov', 'mp4'] }) |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
It would be handy to have an equivalent to the
image()
helper for content collection schemas that can resolve arbitrary assets from a relative path in frontmatter.Background & Motivation
Today we’ve made it easy to turn a local image referenced in frontmatter into an image import using our
image()
helper for content collections schemas. This works well, but users can’t use the same approach for other assets like videos or PDFs, which is not a smooth DX because you need to switch between techniques depending on the type of asset you’re aiming to load.Goals
import
for.Example
Similar to
image()
, use a schema helper to mark a field as needing resolving as an import, something like:Ideally there’d be a way to specify supported file formats?
Content could then set the path:
And a template could use the resolved URL:
Beta Was this translation helpful? Give feedback.
All reactions