Skip to content

Commit

Permalink
Replace manual setup with keystatic integration (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonswiss authored Oct 17, 2023
1 parent da5f848 commit 6b02eec
Showing 1 changed file with 22 additions and 55 deletions.
77 changes: 22 additions & 55 deletions docs/src/content/pages/installation-astro.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,28 @@ You will also need two Keystatic packages:
npm install @keystatic/core @keystatic/astro
```

## Creating a Keystatic config file
## Updating the Astro config

Add the `keystatic` integration in your `astro.config.mjs` file and set the `output` mode to `hybrid`:

```diff
import { defineConfig } from 'astro/config'

import react from '@astrojs/react'
import markdoc from '@astrojs/markdoc'
+ import keystatic from '@keystatic/astro'

// https://astro.build/config
export default defineConfig({
- integrations: [react(), markdoc()],
+ integrations: [react(), markdoc(), keystatic()],
+ output: 'hybrid',
})
```

---

A Keystatic config file is required to define your content schema. This file will also allow you to connect a project to a specific GitHub repository (if you decide to do so).
## Creating a Keystatic config file

Create a file called `keystatic.config.ts` in the root of the project and add the following code to define both your storage type (`local`) and a single content collection (`posts`):

Expand Down Expand Up @@ -63,65 +82,13 @@ export default config({

Keystatic is now configured to manage your content based on your schema.

---

## Setting up the Keystatic Admin UI

First, create a `keystatic.page.ts` file in the project root, alongside your Keystatic config file:

```ts
// keystatic.page.ts
import { makePage } from '@keystatic/astro/ui'
import keystaticConfig from './keystatic.config'

export const Keystatic = makePage(keystaticConfig)
```

Next, create a new page called `src/pages/keystatic/[...params].astro` that mounts the component on the client side only:

```ts
// src/pages/keystatic/[...params].astro
---
import { Keystatic } from '../../../keystatic.page'
export const prerender = false
---

<Keystatic client:only />
```

Create a new file called `src/pages/api/keystatic/[...params].ts` that will create API routes for Keystatic’s Admin UI:

```ts
// src/pages/api/keystatic/[...params].ts
import { makeHandler } from '@keystatic/astro/api'
import keystaticConfig from '../../../../keystatic.config'

export const all = makeHandler({
config: keystaticConfig,
})

export const prerender = false
```
## Running Keystatic

Go to your `package.json` and add `--host 127.0.0.1` to your "dev" script:
```
"dev": "astro dev --host 127.0.0.1"
```

Finally, go to `astro.config.mjs` in the project root and add `output: 'hybrid'` to `defineConfig` options. Your `astro.config.mjs` should look similar to this:
```ts
import { defineConfig } from 'astro/config';
import react from '@astrojs/react';
import markdoc from '@astrojs/markdoc';

// https://astro.build/config
export default defineConfig({
integrations: [react(), markdoc()],
output: 'hybrid',
});

```

You can now launch the Keystatic Admin UI. Start the Astro dev server:

```bash
Expand Down

3 comments on commit 6b02eec

@vercel
Copy link

@vercel vercel bot commented on 6b02eec Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

keystatic – ./dev-projects/next-app

keystatic-thinkmill-labs.vercel.app
keystatic-git-main-thinkmill-labs.vercel.app
keystatic.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6b02eec Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

keystar-ui – ./design-system/docs

keystar-ui-thinkmill-labs.vercel.app
keystar-ui-git-main-thinkmill-labs.vercel.app
voussoir.vercel.app
keystar-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6b02eec Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.