Skip to content

Conversation

@matthewp
Copy link
Contributor

Changes

Testing

  • Added two new test cases in test/content-layer.test.js:
    • loads images with bare filenames in JSON - Tests bare filename resolution
    • loads images with relative paths in JSON - Ensures existing relative path behavior still works
  • Created rockets.json test fixture with both bare filename and relative path examples
  • Tests verify both formats resolve correctly to /_astro paths with proper image metadata
  • All test files are syntactically valid and follow existing test patterns

Docs

N/A, bug fix

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 <[email protected]>
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 <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2025

🦋 Changeset detected

Latest commit: 08f88ce

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Oct 20, 2025
@matthewp matthewp changed the title Claude/review issue solution 011 cu jz v wzjca3so fi vr wxz s Fix bare images used in JSON content collections Oct 20, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 20, 2025

CodSpeed Performance Report

Merging #14590 will not alter performance

Comparing claude/review-issue-solution-011CUJzVWzjca3soFiVrWxzS (08f88ce) with main (7958c6b)1

Summary

✅ 6 untouched

Footnotes

  1. No successful run was found on main (ca1d331) during the generation of this report, so 7958c6b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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 <[email protected]>
@matthewp matthewp marked this pull request as ready for review October 21, 2025 14:04
@matthewp matthewp merged commit 577d051 into main Oct 21, 2025
68 of 73 checks passed
@matthewp matthewp deleted the claude/review-issue-solution-011CUJzVWzjca3soFiVrWxzS branch October 21, 2025 15:25
@astrobot-houston astrobot-houston mentioned this pull request Oct 21, 2025
richardnbanks pushed a commit to richardnbanks/astro-loader-youtube that referenced this pull request Oct 22, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`5.14.6` -> `5.14.8`](https://renovatebot.com/diffs/npm/astro/5.14.6/5.14.8) | [![age](https://developer.mend.io/api/mc/badges/age/npm/astro/5.14.8?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/astro/5.14.6/5.14.8?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [googleapis](https://github.com/googleapis/google-api-nodejs-client) | [`164.0.0` -> `164.1.0`](https://renovatebot.com/diffs/npm/googleapis/164.0.0/164.1.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/googleapis/164.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/googleapis/164.0.0/164.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>withastro/astro (astro)</summary>

### [`v5.14.8`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#5148)

[Compare Source](https://github.com/withastro/astro/compare/[email protected]@5.14.8)

##### Patch Changes

- [#&#8203;14590](withastro/astro#14590) [`577d051`](withastro/astro@577d051) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Fixes image path resolution in content layer collections to support bare filenames. The `image()` helper now normalizes bare filenames like `"cover.jpg"` to relative paths `"./cover.jpg"` for consistent resolution behavior between markdown frontmatter and JSON content collections.

### [`v5.14.7`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#5147)

[Compare Source](https://github.com/withastro/astro/compare/[email protected]@5.14.7)

##### Patch Changes

- [#&#8203;14582](withastro/astro#14582) [`7958c6b`](withastro/astro@7958c6b) Thanks [@&#8203;florian-lefebvre](https://github.com/florian-lefebvre)! - Fixes a regression that caused Actions to throw errors while loading

- [#&#8203;14567](withastro/astro#14567) [`94500bb`](withastro/astro@94500bb) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Fixes the actions endpoint to return 404 for non-existent actions instead of throwing an unhandled error

- [#&#8203;14566](withastro/astro#14566) [`946fe68`](withastro/astro@946fe68) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Fixes handling malformed cookies gracefully by returning the unparsed value instead of throwing

  When a cookie with an invalid value is present (e.g., containing invalid URI sequences), `Astro.cookies.get()` now returns the raw cookie value instead of throwing a URIError. This aligns with the behavior of the underlying `cookie` package and prevents crashes when manually-set or corrupted cookies are encountered.

- [#&#8203;14142](withastro/astro#14142) [`73c5de9`](withastro/astro@73c5de9) Thanks [@&#8203;P4tt4te](https://github.com/P4tt4te)! - Updates handling of CSS for hydrated client components to prevent duplicates

- [#&#8203;14576](withastro/astro#14576) [`2af62c6`](withastro/astro@2af62c6) Thanks [@&#8203;aprici7y](https://github.com/aprici7y)! - Fixes a regression that caused `Astro.site` to always be `undefined` in `getStaticPaths()`

</details>

<details>
<summary>googleapis/google-api-nodejs-client (googleapis)</summary>

### [`v164.1.0`](https://github.com/googleapis/google-api-nodejs-client/blob/HEAD/CHANGELOG.md#16410-2025-10-20)

[Compare Source](googleapis/google-api-nodejs-client@googleapis-v164.0.0...googleapis-v164.1.0)

##### Features

- run the generator ([#&#8203;3820](googleapis/google-api-nodejs-client#3820)) ([fd02f58](googleapis/google-api-nodejs-client@fd02f58))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS45OS4xMSIsInVwZGF0ZWRJblZlciI6IjQxLjk5LjExIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://code.richardbanks.dev/richard/astro-loader-youtube/pulls/22
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
@kslstn
Copy link

kslstn commented Nov 14, 2025

Thanks, this is very good. In fact, so good, that it caught some issues in my data I wasn't aware of. I spent quite a bit of time trying to figure out what was causing the error. Maybe this is not the best place to leave this information, but it's the page I found, searching for the description of the problem. So maybe it's of help to someone else.

What went wrong: I had both relative and absolute image paths in the JSON. Where in previous versions this worked: "image": "src/assets/my-image.jpg", that now causes an error:

Could not find requested image ./src/assets/my-image.jpg. Does it exist?

The correct way of providing the path is "image": "/src/assets/my-image.jpg".

Now that I'm writing this down, I wonder: is that error message even correct? Because:

  1. The image actually is located at ./src/assets/my-image.jpg.
  2. In Astro projects, the path ./src/assets/my-image.jpg. equals src/assets/my-image.jpg, right?

@florian-lefebvre
Copy link
Member

Hey @kslstn! I think there was an issue about this regression but I cannot find it. Can you open a new issue so it doesn't get lost? Thanks

@kslstn
Copy link

kslstn commented Nov 14, 2025

Sure, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants