Skip to content

Commit

Permalink
[Content collections] Add .astro directory setup (withastro#2313)
Browse files Browse the repository at this point in the history
* new: add `.astro` directory notes

* edit: manual instructions -> auto instructions

* edit: add `src/env.d.ts` note to `astro sync`

* edit: add type ref that's inserted

* edit: the following -> will be created

* new: add "run astro dev" instructions to getting started

Co-authored-by: Chris Swithinbank <[email protected]>
  • Loading branch information
bholmesdev and delucis authored Jan 12, 2023
1 parent a37e437 commit 5c52a20
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/pages/en/guides/content-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Content collections help organize your Markdown or MDX and type-check your front

## Getting started

First, run the [`astro dev`](/en/reference/cli-reference/#astro-dev), [`astro build`](/en/reference/cli-reference/#astro-build), or [`astro sync`](/en/reference/cli-reference/#astro-sync) commands to generate types. This will make the `astro:content` module available for [querying](#querying-content-collections) and [configuring](#configuring-collections) your content collections.

Content Collections are experimental. To enable this feature, set the `experimental.contentCollections` flag in your Astro config:

```js
Expand Down Expand Up @@ -79,7 +81,20 @@ To benefit from the full TypeScript and autocompletion features of [using schema
</Fragment>
</TypeScriptSettingTabs>

### Set up the `.astro` directory

Astro generates TypeScript types from your content collections in the `.astro` directory. These types will be updated anytime you run the [`astro dev`](/en/reference/cli-reference/#astro-dev), [`astro build`](/en/reference/cli-reference/#astro-build), or [`astro sync`](/en/reference/cli-reference/#astro-sync) commands.

:::tip
If you're using Git for version control, we recommend ignoring this generated directory by adding `.astro` to your `.gitignore`.
:::

These commands will also generate a [reference path](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-path-) to include `.astro` types in your project. A [`src/env.d.ts` file](/en/guides/typescript/#setup) will be created for you if one does not exist, and the following will be added:

```ts title="src/env.d.ts"
// using a relative path `../` to the `.astro` directory
/// <reference types="../.astro/types.d.ts" />
```

## The content directory

Expand Down
6 changes: 5 additions & 1 deletion src/pages/en/reference/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ This command only checks types within `.astro` files.
<Since v="1.7.0" />
</p>

Generates TypeScript types for all Astro modules. Today, this includes the `astro:content` module for the (experimental) [Content Collections API](/en/guides/content-collections/).
:::tip
Running `astro dev` or `astro build` will run the `sync` command as well.
:::

Generates TypeScript types for all Astro modules. This sets up a [`src/env.d.ts` file](/en/guides/typescript/#setup) for type inferencing, and defines the `astro:content` module for the (experimental) [Content Collections API](/en/guides/content-collections/).

## `astro add`

Expand Down

0 comments on commit 5c52a20

Please sign in to comment.