#using reference with nested folders

3 messages · Page 1 of 1 (latest)

undone gardenBOT
#

Hi @wicked tulip. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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:

  1. Collection Entry IDs: In Astro v5, content collections use id instead of slug. As mentioned in the Upgrade to Astro v5 guide, you need to change references from slug to id. This might affect how you're referencing the English version from the French post.

  2. File Path as ID: The id of your content entries is likely including the full path, including the language folder. So, your English post's id might be en/best-vscode-extensions-for-front-end-developers/index rather than just best-vscode-extensions-for-front-end-developers.

  3. Reference Format: When using the reference() function, you need to provide the full id of the entry you're referencing.

Given these points, you might try modifying your schema and frontmatter like this:

  1. 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(),
    }),
});
  1. 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.

Remember, the exact behavior might depend on the specific version of Astro you're using and any other configuration in your project. If the problem persists, you might want to reach out to the Astro community or file an issue on the Astro GitHub repository for more tailored assistance.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: