#How to get the original file path of a CollectionEntry?
1 messages · Page 1 of 1 (latest)
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.