|
1 |
| -# A minimal SvelteKit site with Sanity Studio |
| 1 | +# Clean SvelteKit + Sanity app |
2 | 2 |
|
3 |
| -This starter uses [SvelteKit](https://kit.svelte.dev/) for the frontend and [Sanity](https://sanity.io/) to handle its content. |
| 3 | +This template includes a [SvelteKit](https://svelte.dev/docs/kit/introduction) app with a [Sanity Studio](https://www.sanity.io/) – an open-source React application that connects to your Sanity project’s hosted dataset. The Studio is configured locally and can then be deployed for content collaboration. |
4 | 4 |
|
5 |
| -## Featuring |
| 5 | +## Features |
6 | 6 |
|
7 |
| -- How to fetch content as data from [the Sanity Content Lake](https://www.sanity.io/docs/datastore) |
8 |
| -- How to render block content with [Portable Text](https://www.sanity.io/docs/presenting-block-text) |
9 |
| -- A [Sanity Studio](https://www.sanity.io/docs/sanity-studio) to create and edit content |
10 |
| -- Visual editing with live updates through [Presentation](https://www.sanity.io/docs/presentation) |
11 |
| -- How to crop and render images with [Sanity Image URLs](https://www.sanity.io/docs/image-url) |
| 7 | +- Fetch content seamlessly with [Sanity Content Lake](https://www.sanity.io/docs/datastore). |
| 8 | +- Render beautiful block content using [Portable Text](https://www.sanity.io/docs/presenting-block-text). |
| 9 | +- Manage and create content with the intuitive [Sanity Studio](https://www.sanity.io/docs/sanity-studio). |
| 10 | +- Live visual editing through [Sanity's Presentation tools](https://www.sanity.io/docs/presentation). |
| 11 | +- Advanced image cropping and rendering via [Sanity Image URLs](https://www.sanity.io/docs/image-url). |
12 | 12 |
|
13 |
| -> **Note** |
14 |
| -> |
15 |
| -> This starter features an `/app` and a `/studio` folder. The `/app` folder contains the frontend code, and the `/studio` folder contains the Sanity Studio code. |
16 |
| -> |
17 |
| -> It is configured as a monorepo using [pnpm workspaces](https://pnpm.io/workspaces), but you can treat these directories as separate projects if you prefer. |
| 13 | +## Demo |
18 | 14 |
|
19 |
| -## Prerequisities |
| 15 | +https://sanity-template-sveltekit-clean.sanity.build |
20 | 16 |
|
21 |
| -- [Node.js](https://nodejs.org/en/) (v14.18 or later) |
22 |
| -- [Sanity CLI](https://www.sanity.io/docs/getting-started-with-sanity-cli) (optional) |
| 17 | +## Getting Started |
23 | 18 |
|
24 |
| -## Getting started |
| 19 | +### Install the template |
25 | 20 |
|
26 |
| -Run the following commands to prepare both applications, each step should be executed from the **root directory**: |
| 21 | +#### 1. Initialize template with Sanity CLI |
27 | 22 |
|
28 |
| -1. Install dependencies. |
| 23 | +Run the command in your Terminal to initialize this template on your local computer. |
29 | 24 |
|
30 |
| -```sh |
31 |
| -pnpm install |
| 25 | +See the documentation if you are [having issues with the CLI](https://www.sanity.io/help/cli-errors). |
| 26 | + |
| 27 | +```shell |
| 28 | +npm create sanity@latest -- --template sanity-template-sveltekit-clean |
32 | 29 | ```
|
33 | 30 |
|
34 |
| -2. Select or create a Sanity project and dataset, and output the details to a `.env` file. |
| 31 | +#### 2. Run the application and Sanity Studio |
| 32 | + |
| 33 | +Navigate to the template directory using `cd <your app name>`, and start the development servers by running the following command |
35 | 34 |
|
36 |
| -```sh |
37 |
| -cd studio && pnpm sanity init --env .env |
| 35 | +```shell |
| 36 | +npm run dev |
38 | 37 | ```
|
39 | 38 |
|
40 |
| -3. [Generate a token](https://www.sanity.io/docs/http-auth#4c21d7b829fe) with read permissions for use in the next step. |
| 39 | +#### 3. Open the app and sign in to the Studio |
41 | 40 |
|
42 |
| -```sh |
43 |
| -pnpm sanity manage |
44 |
| -``` |
| 41 | +Open the SvelteKit app running locally in your browser on [http://localhost:5173](http://localhost:5173). |
45 | 42 |
|
46 |
| -4. Copy the example app `.env` file and populate it with the required values. |
| 43 | +Open the Studio running locally in your browser on [http://localhost:3333](http://localhost:3333). You should now see a screen prompting you to log in to the Studio. Use the same service (Google, GitHub, or email) that you used when you logged in to the CLI. |
47 | 44 |
|
48 |
| -```sh |
49 |
| -cp ./app/.env.example ./app/.env |
50 |
| -``` |
| 45 | +### Adding content with Sanity |
| 46 | + |
| 47 | +#### 1. Publish your first document |
| 48 | + |
| 49 | +The template comes pre-defined with a schema containing a `Post` document type. |
| 50 | + |
| 51 | +From the Studio, click "+ Create" and select the `Post` document type. Go ahead and create and publish the document. |
| 52 | + |
| 53 | +Your content should now appear in your SvelteKit app ([http://localhost:5173](http://localhost:5173)) as well as in the Studio on the "Presentation" Tab |
| 54 | + |
| 55 | +#### 2. Extending the Sanity schema |
| 56 | + |
| 57 | +The schema for the `Post` document type is defined in the `studio/src/schemaTypes/post.ts` file. You can [add more document types](https://www.sanity.io/docs/schema-types) to the schema to suit your needs. |
| 58 | + |
| 59 | +### Deploying your application and inviting editors |
| 60 | + |
| 61 | +#### 1. Deploy Sanity Studio |
| 62 | + |
| 63 | +Your SvelteKit frontend (`/sveltekit-app`) and Sanity Studio (`/studio`) are still only running on your local computer. It's time to deploy and get it into the hands of other content editors. |
51 | 64 |
|
52 |
| -5. Start the development servers: |
| 65 | +Back in your Studio directory (`/studio`), run the following command to deploy your Sanity Studio. |
53 | 66 |
|
54 |
| -```sh |
55 |
| -pnpm dev |
| 67 | +```shell |
| 68 | +npx sanity deploy |
56 | 69 | ```
|
57 | 70 |
|
58 |
| -- Your SvelteKit app should now be running on [http://localhost:5173/](http://localhost:5173/). |
59 |
| -- Your Studio should now be running on [http://localhost:3333/](http://localhost:3333/). |
| 71 | +#### 2. Deploy SvelteKit app to Vercel |
60 | 72 |
|
61 |
| -### Add content |
| 73 | +You have the freedom to deploy your SvelteKit app to your hosting provider of choice. With Vercel and GitHub being a popular choice, we'll cover the basics of that approach. |
62 | 74 |
|
63 |
| -1. Visit the Studio and create and publish a new `Post` document |
64 |
| -2. Visit the App and refresh the page to see your content rendered on the page |
| 75 | +1. Create a GitHub repository from this project. [Learn more](https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github). |
| 76 | +2. Create a new Vercel project and connect it to your Github repository. |
| 77 | +3. Set the `Root Directory` to your SvelteKit app. |
| 78 | +4. Configure your Environment Variables. |
65 | 79 |
|
66 |
| -The schema for the `Post` document is defined in the `/studio/schemas` folder. You can add more documents and schemas to the Studio to suit your needs. |
| 80 | +#### 3. Invite a collaborator |
67 | 81 |
|
68 |
| -## Deployments |
| 82 | +Now that you’ve deployed your SvelteKit application and Sanity Studio, you can optionally invite a collaborator to your Studio. Open up [Manage](https://www.sanity.io/manage), select your project and click "Invite project members" |
69 | 83 |
|
70 |
| -The `/app` and `/studio` folders are meant to be deployed separately. |
| 84 | +They will be able to access the deployed Studio, where you can collaborate together on creating content. |
71 | 85 |
|
72 |
| -Make sure that after `/app` is deployed the `.env` file in `/studio` is updated with its deployment URL under `SANITY_STUDIO_PREVIEW_URL`. |
| 86 | +## Resources |
73 | 87 |
|
74 |
| -And `/app` has a `.env` file with `PUBLIC_SANITY_STUDIO_URL` that points to the Studio's deployment URL. |
| 88 | +- [Sanity documentation](https://www.sanity.io/docs/) |
| 89 | +- [SvelteKit documentation](https://svelte.dev/docs/kit/introduction/) |
| 90 | +- [Join the Sanity Community](https://slack.sanity.io) |
| 91 | +- [Learn Sanity](https://www.sanity.io/learn) |
0 commit comments