Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for TanStack Start #458

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .better-commits.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
"label": "next"
},
{
"value": "solid-start",
"label": "solid-start"
"value": "vinxi",
"label": "vinxi"
},
{
"value": "mdx",
Expand Down
2 changes: 1 addition & 1 deletion .commitlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"vite",
"remix-vite",
"next",
"solid-start",
"vinxi",
"mdx",
"markdown",
"shared"
Expand Down
4 changes: 4 additions & 0 deletions docs/adapter/solid-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ description: Use Content Collections with Solid Start

The `@content-collections/solid-start` package enables easy integration of Content Collections into your SolidStart app. It includes a SolidStart plugin that automatically creates content collections and incorporates them into the build process.

<Callout type="warn" title='Warning'>
**Deprecated:** This adapter is deprecated. Please use the [vinxi](/docs/adapter/vinxi) adapter instead.
</Callout>

## Installation

<div className="steps">
Expand Down
65 changes: 65 additions & 0 deletions docs/adapter/vinxi.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: Vinxi
description: Use Content Collections with Vinxi based frameworks
---

The `@content-collections/vinxi` package facilitates the seamless integration of Content Collections with frameworks based on [vinxi](https://vinxi.vercel.app/) like [SolidStart](https://start.solidjs.com/) or [TanStack Start](https://tanstack.com/start/latest). It includes a Vite plugin designed specifically for vinxi, preventing multiple executions of Content Collections. The plugin automatically integrates Content Collections into the build process.

## Installation

<div className="steps">
<div className="step">

Install required packages:

We have to install the following packages:

- `@content-collections/core`
- `@content-collections/vinxi`

```package-install
npm i @content-collections/core @content-collections/vinxi -D
```

</div>
<div className="step">

After installation, we have to add a path alias for the generated collections to the `tsconfig.json`:

```json
{
"compilerOptions": {
// ...
"paths": {
"~/*": ["./src/*"],
"content-collections": ["./.content-collections/generated"]
}
}
}
```

</div>
<div className="step">

To enable the content collections plugin we have to add the plugin to the array of vite plugins in the (`app.config.ts`):

```ts
import { defineConfig } from "@solidjs/start/config";
import contentCollections from "@content-collections/vinxi";
export default defineConfig({
vite: {
plugins: [contentCollections()],
},
});
```

</div>
</div>

## API

The package exports a single function as the default export. The function takes a single argument, an object with the following properties:

### `configPath` (optional)

Specifies the path to the Content Collections configuration file. Defaults to `content-collections.ts`.
1 change: 1 addition & 0 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The automatic installation currently supports the following frameworks:
- Qwik
- SvelteKit
- SolidStart
- TanStack Start
- Vite

To install Content Collections automatically, run the following command in your project's directory:
Expand Down
10 changes: 5 additions & 5 deletions docs/quickstart/solid-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Install required packages:
We have to install the following packages:

- `@content-collections/core`
- `@content-collections/solid-start`
- `@content-collections/vinxi`

```package-install
npm i @content-collections/core @content-collections/solid-start -D
npm i @content-collections/core @content-collections/vinxi -D
```

</div>
Expand Down Expand Up @@ -47,16 +47,16 @@ Modify your `app.config.ts`:

```ts
import { defineConfig } from "@solidjs/start/config";
import contentCollections from "@content-collections/solid-start";
import contentCollections from "@content-collections/vinxi";
export default defineConfig({
vite: {
plugins: [contentCollections()],
},
});
```

Add the Content Collections plugin to your Vite config.
For more details on the SolidStart adapter, refer to the [documentation](/docs/adapter/solid-start)
Add the Content Collections plugin to your Vinxi config.
For more details on the Vinxi adapter, refer to the [documentation](/docs/adapter/vinxi).

</div>
<div className="step">
Expand Down
155 changes: 155 additions & 0 deletions docs/quickstart/tanstack-start.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
title: TanStack Start
description: Use Content Collections with TanStack Start
linkText: Quickstart TanStack Start
icon: tanstack
category: frameworks
---

<div className="steps">
<div className="step">

Install required packages:

We have to install the following packages:

- `@content-collections/core`
- `@content-collections/vinxi`

```package-install
npm i @content-collections/core @content-collections/vinxi -D
```

</div>
<div className="step">

Adjust your `tsconfig.json`:

```json
{
"compilerOptions": {
// ...
"paths": {
"~/*": ["./app/*"],
"content-collections": ["./.content-collections/generated"]
}
}
}
```

We require a path alias for the generated files.
This is necessary because we will generate the files in the `.content-collections/generated` folder.

</div>
<div className="step">

Modify your `app.config.ts`:

```ts
import contentCollections from "@content-collections/vinxi";
import { defineConfig } from "@tanstack/start/config";
import tsConfigPaths from "vite-tsconfig-paths";

export default defineConfig({
vite: {
plugins: [
contentCollections(),
tsConfigPaths({
projects: ["./tsconfig.json"],
}),
],
},
});
```

Add the Content Collections plugin to your Vinxi config.
For more details on the Vinxi adapter, refer to the [documentation](/docs/adapter/vinxi).

</div>
<div className="step">

Add the new `.content-collections` directory to your project's `.gitignore` file — the files in this directory are always regenerated and can be safely ignored by Git.

```
.content-collections
```

</div>
<div className="step">

Create a `content-collections.ts` file at the root of your project:

```ts
import { defineCollection, defineConfig } from "@content-collections/core";

const posts = defineCollection({
name: "posts",
directory: "content/posts",
include: "**/*.md",
schema: (z) => ({
title: z.string(),
summary: z.string(),
}),
});

export default defineConfig({
collections: [posts],
});
```

This file defines a collection named `posts` in the `content/posts` folder.
The collection will include all markdown files (`**/*.md`) and the schema will validate the `title` and `summary` fields.

For more information about the configuration have a look at the [documentation](/docs/configuration).

</div>
<div className="step">

Create your content files (e.g.: `content/posts/hello-world.md`):

```md
---
title: "Hello world"
summary: "This is my first post!"
---

# Hello world

This is my first post!
... rest of the content
```

You can create unlimited content files.
These files will be validated against the schema defined in the `content-collections.ts` file.
If the files are valid, they will be automatically added to the `posts` collection.

</div>
<div className="step">

Usage in your code:

```tsx
import { allPosts } from "content-collections";

export function Posts() {
return (
<ul>
{allPosts.map((post) => (
<li>
<a href={`/posts/${post._meta.path}`}>
<h3>{post.title}</h3>
<p>{post.summary}</p>
</a>
</li>
))}
</ul>
);
}
```

Now you can just import the `allPosts` collection and use it in your code.
The `allPosts` collection will contain all posts that are valid.
The `post` object will contain the `title`, `summary` and `content` fields as well as some meta information in the `_meta` field.

</div>
</div>
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@
"turbo": "^2.2.3"
},
"prettier": "@content-collections/prettier-config",
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"vite": "5.4.11"
}
}
}
14 changes: 14 additions & 0 deletions packages/installer/src/migration/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ describe("findMigrator", () => {
expect(migrator.name).toBe("remix");
});

it("should find tanstack migrator", () => {
const migrator = findMigrator({
name: "tanstack",
dependencies: {
"@tanstack/start": "^1.95.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"vinxi": "0.5.1"
},
});
expect(migrator).not.toBe(null);
expect(migrator.name).toBe("tanstack");
});

it("should throw error if migrator could not be found", () => {
expect(() =>
findMigrator({
Expand Down
6 changes: 4 additions & 2 deletions packages/installer/src/migration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { Migrator } from "./migrator.js";
import { migratorNextJS } from "./next.js";
import { migratorQwik } from "./qwik.js";
import { migratorRemix } from "./remix.js";
import { migratorSolid } from "./solid.js";
import { migratorVinxi } from "./vinxi.js";
import { migratorVite } from "./vite.js";
import { migratorSvelteKit } from "./sveltekit.js";
import { migratorTanStack } from "./tanstack.js";

const migrators = [
migratorNextJS,
migratorRemix,
migratorQwik,
migratorSolid,
migratorTanStack,
migratorVinxi,
migratorSvelteKit,
migratorVite,
];
Expand Down
Loading
Loading