Commit 577d051
Fix bare images used in JSON content collections (#14590)
* fix(content): normalize bare filenames in content layer image() helper
Fixes #14456
The image() helper in content layer collections now normalizes bare
filenames (e.g., "cover.jpg") to relative paths (e.g., "./cover.jpg")
to ensure consistent resolution behavior with markdown frontmatter.
Without this normalization, bare filenames were passed directly to
Vite's resolver, which treated them as package imports rather than
relative file references, causing resolution failures.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test(content): add test for bare filename images in JSON collections
Adds a test case to verify that bare filenames (e.g., "cover.jpg")
work correctly in JSON content layer collections with the image()
helper, ensuring they are resolved the same way as in markdown
frontmatter.
The test includes:
- New rockets.json fixture with bare filename and relative path images
- Test assertions for both bare filename and relative path resolution
- Updated collections.json.js to include the new collection
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* chore: add changeset for image path resolution fix
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(content): exclude aliases and parent paths from normalization
Updates the bare filename normalization to properly skip:
- Alias paths starting with ~ (e.g., ~/assets/image.jpg)
- Alias paths starting with @ (e.g., @images/image.jpg)
- Parent directory paths starting with ../ (e.g., ../image.jpg)
This prevents breaking existing alias resolution while still
normalizing true bare filenames like "cover.jpg" to "./cover.jpg".
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d5bdbc0 commit 577d051Copy full SHA for 577d051
7 files changed
+67-4Lines changed: 67 additions & 4 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- .changeset
- packages/astro
- src/content
- test
- fixtures/content-layer/src
- data
- pages
Expand file treeCollapse file tree
Open diff view settings
Collapse file
.changeset/neat-images-resolve.md
Copy file name to clipboard+5Lines changed: 5 additions & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
Collapse file
packages/astro/src/content/utils.ts
Copy file name to clipboardExpand all lines: packages/astro/src/content/utils.ts+21-2Lines changed: 21 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
184 | 184 | |
185 | 185 | |
186 | 186 | |
187 | | - |
188 | | - |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
189 | 208 | |
190 | 209 | |
191 | 210 | |
|
Collapse file
packages/astro/test/content-layer.test.js
Copy file name to clipboardExpand all lines: packages/astro/test/content-layer.test.js+10Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
281 | 281 | |
282 | 282 | |
283 | 283 | |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
284 | 294 | |
285 | 295 | |
286 | 296 | |
|
Collapse file
packages/astro/test/fixtures/content-layer/src/content.config.ts
Copy file name to clipboardExpand all lines: packages/astro/test/fixtures/content-layer/src/content.config.ts+12Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
253 | 253 | |
254 | 254 | |
255 | 255 | |
| 256 | + |
| 257 | + |
| 258 | + |
| 259 | + |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | + |
| 264 | + |
| 265 | + |
| 266 | + |
256 | 267 | |
257 | 268 | |
258 | 269 | |
| ||
270 | 281 | |
271 | 282 | |
272 | 283 | |
| 284 | + |
273 | 285 | |
274 | 286 | |
275 | 287 | |
|
Collapse file
packages/astro/test/fixtures/content-layer/src/data/rockets.json
Copy file name to clipboard+14Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
Collapse file
packages/astro/test/fixtures/content-layer/src/data/shuttle.jpg
Copy file name to clipboard170 KB- Display the source diff
- Display the rich diff
Loading
Collapse file
packages/astro/test/fixtures/content-layer/src/pages/collections.json.js
Copy file name to clipboardExpand all lines: packages/astro/test/fixtures/content-layer/src/pages/collections.json.js+5-2Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | | - |
| 37 | + |
| 38 | + |
| 39 | + |
38 | 40 | |
39 | 41 | |
40 | 42 | |
| ||
55 | 57 | |
56 | 58 | |
57 | 59 | |
58 | | - |
| 60 | + |
| 61 | + |
59 | 62 | |
60 | 63 | |
61 | 64 | |
|
0 commit comments