Skip to content

image helper for Content Collection not resolving images with certain relative path for json #14456

@mglsj

Description

@mglsj

Astro Info

Astro                    v5.14.1
Vite                     v6.3.6
Node                     v24.7.0
System                   Windows (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The image() helper in the Content Collection schema is not resolving images that have relative path without ./ only in json files. It works when the content is in .md frontmatter

content.config.ts

const md = defineCollection({
	loader: glob({ base: 'content/md', pattern: '**/*.md' }),
	schema: ({ image }) =>
		z.object({
			title: z.string(),
			cover: image().optional(),
		}),
});

const json = defineCollection({
	loader: glob({ base: 'content/json', pattern: '**/*.json' }),
	schema: ({ image }) =>
		z.object({
			title: z.string(),
			cover: image().optional(),
		}),
});

index.json

{
    "title": "Second Post JSON",
    "cover": "cover2.jpg",
    "_content": "This is the content of the second post in JSON format."
}

index.md

---
title: "First Post Markdown"
cover: "cover1.jpg"
---

This is the content of the first post in Markdown format.

What's the expected result?

Relative paths to resolve uniformly.

Link to Minimal Reproducible Example

https://stackblitz.com/github/mglsj/astro_issue

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)feat: content collectionsRelated to the Content Collections feature (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions