#How to get the original file path of a CollectionEntry?

1 messages · Page 1 of 1 (latest)

drowsy echo
#

How?

shrewd lightBOT
#

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

#

The original file path of a CollectionEntry is not directly accessible through the Astro API. However, the id property of a CollectionEntry provides a unique identifier using the file path relative to src/content/[collection]. This id includes all possible string values based on the collection entry file paths.

For content collections, the id is something like 'entry-1.md' | 'entry-2.md' | ..., and for data collections, it's like 'author-1' | 'author-2' | ...'. Collections defined as type: 'content' include the file extension in their ID, while collections defined as type: 'data' do not.

Here's an example of how you might use it:

import type { CollectionEntry } from 'astro:content';

// Assuming you have a CollectionEntry object
let entry: CollectionEntry;

console.log(`src/content/[collection]/${entry.id}`);

Please note that you'll need to replace [collection] with the actual name of the collection.

For more details, you can refer to the Astro API Reference (https://docs.astro.build/en/reference/api-reference/#collection-entry-type).

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