#src/content vs src/data

8 messages · Page 1 of 1 (latest)

coral perch
#

What's the difference?

fickle otterBOT
#

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

#

In Astro, the primary difference between these two directories is how they are treated by the framework.

src/content/

This is a reserved directory in Astro. It is specifically designed to store Content Collections, which are a powerful way to manage Markdown, MDX, and JSON/YAML data with type safety.

  • Reserved Use: No files other than content collections and an optional configuration file are allowed inside this folder [Project Structure].
  • Validation: Astro uses this directory to validate your frontmatter schema and provide automatic TypeScript types for your content [Project Structure].

src/data/

Unlike src/content/, the src/data/ directory is not reserved and is not part of Astro's required project structure.

  • Community Convention: While it is a common convention to use a data/ folder for local data files, Astro does not give it special meaning [Project Structure].
  • Flexibility: You are free to create, rename, or reorganize this directory however you like, as Astro only reserves src/pages/ and src/content/ [Project Structure].
#

Summary of Differences

Feature src/content/ src/data/
Status Reserved by Astro Optional Convention
Purpose Managed Content Collections General purpose storage
Type Safety Automatic TypeScript support Manual handling
Restrictions Only collections allowed No restrictions

In short, use src/content/ when you want to take advantage of Astro's built-in content management features, and use a directory like src/data/ for other local assets or files that don't fit the content collection model [Project Structure].

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

#

@coral perch Kapa.ai is still learning and improving, please let me know how I did by reacting below.

coral perch
#

@fickle otter Then what is directory for Content Layer API?

fickle otterBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

I'm sorry, but the provided knowledge sources do not contain information regarding a specific directory for a "Content Layer API."

The available documentation focuses on the standard Content Collections API, which is hosted in the src/content/ directory [Project Structure]. This directory is reserved for storing collections and their configuration files, and it is where Astro manages metadata and type safety through the internal .astro directory [What are Content Collections?].

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