Skip to content

feat(preview): add useMediaPath(path) to resolve media URLs for Studio preview #3507

@maximepvrt

Description

@maximepvrt

Is your feature request related to a problem? Please describe

In Content Studio Preview, media paths only work correctly when returned directly from Content composables.
If a media path is dynamically built (e.g. ${p.path}/thumbnail.jpg), the URL is not rewritten/proxied in Preview, so the image does not load, even though it works fine in production.

Describe the solution you'd like

Introduce a composable useMediaPath(path) that resolves a media path to the correct URL depending on the context:

  • In Preview: return a proxied/rewritten URL so the asset loads.
  • Outside Preview: returns the path param.

Example usage:

const { data: posts } = await useAsyncData(
  'posts',
  () => queryCollection('blog').order('date', 'DESC').all(),
  {
    transform: (posts) => posts.map((p) => {
      p.image = useMediaPath(`${p.path}/thumbnail.jpg`)
      p.to = p.path
      return p
    })
  }
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions