#using reference with nested folders
3 messages · Page 1 of 1 (latest)
Based on the information provided in the knowledge sources, I can offer some insights into your issue with content collections and references in Astro v5. However, the specific error you're encountering isn't directly addressed in the provided documentation. Let's break down the problem and suggest some potential solutions.
The error message suggests that the reference to the English version from the French post is not being resolved correctly. This could be due to how Astro is interpreting the file paths in your content collection.
Here are a few things to consider:
-
Collection Entry IDs: In Astro v5, content collections use
idinstead ofslug. As mentioned in the Upgrade to Astro v5 guide, you need to change references fromslugtoid. This might affect how you're referencing the English version from the French post. -
File Path as ID: The
idof your content entries is likely including the full path, including the language folder. So, your English post'sidmight been/best-vscode-extensions-for-front-end-developers/indexrather than justbest-vscode-extensions-for-front-end-developers. -
Reference Format: When using the
reference()function, you need to provide the fullidof the entry you're referencing.
Given these points, you might try modifying your schema and frontmatter like this:
- Update your schema to expect the full path:
const blogCollection = defineCollection({
loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: "./src/content/blog" }),
schema: ({ image }) =>
z.object({
title: z.string(),
description: z.string(),
defaultLocaleVersion: reference("blog").optional(),
}),
});
- In your French post's frontmatter, reference the English post with its full path:
---
title: "Meilleures extensions VSCode pour développeurs front-end"
description: "..."
defaultLocaleVersion: "en/best-vscode-extensions-for-front-end-developers/index"
---
If this doesn't resolve the issue, you might need to double-check that the file paths in your reference() exactly match the ids that Astro is generating for your content entries. You can log these ids when querying your collection to verify the correct paths.
If you continue to face issues, it might be helpful to consult the Astro documentation on defining collection references for more detailed information on how to properly set up references between content entries.