# Collection

One collection's documents. Everything is built ahead of time, so reads are synchronous.

> Every page: https://tomekit.aayush.cv/llms.txt

Defined in: [query.ts:39](https://github.com/aayushbtw/tomekit/blob/main/packages/tomekit/src/query.ts#L39)

One collection's documents. Everything is built ahead of time, so reads are synchronous.

## Example

```ts
import { posts } from "tomekit/content";

posts.documents().filter((post) => post.metadata.tags.includes("vite"));
posts.get("hello-world").metadata.title;
posts.slugs(); // ["hello-world", "setup"]
```

## Methods

### documents()

```ts
documents(this: void): readonly TDocument[];
```

Defined in: [query.ts:45](https://github.com/aayushbtw/tomekit/blob/main/packages/tomekit/src/query.ts#L45)

Every document, in the order its loader returned them, eg file name order for `directory`. Sort, filter and slice it like any array.

***

### get()

```ts
get(this: void, slug: TKnownSlug): TDocument;
```

Defined in: [query.ts:58](https://github.com/aayushbtw/tomekit/blob/main/packages/tomekit/src/query.ts#L58)

The document with this slug. A slug that exists returns its document.

```ts
posts.get("hello-world").metadata.title;
```

```ts
get<TKey extends string>(this: void, slug: LookupKey<TKey, TKnownSlug>): TDocument | undefined;
```

Defined in: [query.ts:69](https://github.com/aayushbtw/tomekit/blob/main/packages/tomekit/src/query.ts#L69)

The document with this slug, or `undefined` if there is none, eg for a route param.

```ts
const post = posts.get(params.slug);
if (!post) throw notFound();
```

***

### has()

```ts
has(this: void, slug: string): slug is TSlug;
```

Defined in: [query.ts:83](https://github.com/aayushbtw/tomekit/blob/main/packages/tomekit/src/query.ts#L83)

Whether a document has this slug. Narrows a route param to the collection's slugs, so `get` then returns the document.

```ts
if (posts.has(params.slug)) posts.get(params.slug).metadata.title;
```

***

### slugs()

```ts
slugs(this: void): readonly TSlug[];
```

Defined in: [query.ts:85](https://github.com/aayushbtw/tomekit/blob/main/packages/tomekit/src/query.ts#L85)

Every slug, in the same order as `documents()`.
