https://github.com/SimeonGriggs/sanity-react-router-template
Sanity Studio v3 embedded into a Remix Vite application configured for Vercel hosting with visual editing
https://github.com/SimeonGriggs/sanity-react-router-template
react remix sanity tailwindcss template
Last synced: 3 months ago
JSON representation
Sanity Studio v3 embedded into a Remix Vite application configured for Vercel hosting with visual editing
- Host: GitHub
- URL: https://github.com/SimeonGriggs/sanity-react-router-template
- Owner: SimeonGriggs
- Created: 2022-09-15T19:56:12.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-01T14:43:07.000Z (about 1 year ago)
- Last Synced: 2024-11-17T01:01:00.086Z (11 months ago)
- Topics: react, remix, sanity, tailwindcss, template
- Language: TypeScript
- Homepage: https://sanity-remix-template.sanity.build
- Size: 12.9 MB
- Stars: 164
- Watchers: 6
- Forks: 35
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Full-featured Sanity Studio + React Router Template
Batteries-included [React Router 7](https://reactrouter.com) website using Vite with [Vercel's deployment preset](https://vercel.com/docs/frameworks/react-router) with [Visual Editing](https://www.sanity.io/docs/visual-editing) for interactive live-preview inside [Presentation](https://www.sanity.io/docs/presentation) powered by an embedded [Sanity Studio](https://www.sanity.io/studio).

[Sanity Docs](https://sanity.io/docs) | [React Router Docs](https://reactrouter.com/home)
- [Full-featured Sanity Studio + React Router Template](#full-featured-sanity-studio--react-router-template)
- [Installation: As a Sanity project template](#installation-as-a-sanity-project-template)
- [Installation: As a React Router template](#installation-as-a-react-router-template)
- [Seed the Studio with fake content](#seed-the-studio-with-fake-content)
- [Includes](#includes)
- [Embedded Studio](#embedded-studio)
- [Visual Editing for interactive live preview inside Presentation](#visual-editing-for-interactive-live-preview-inside-presentation)
- [Pre-configured Studio](#pre-configured-studio)
- [Portable Text component](#portable-text-component)
- [Image URL builder](#image-url-builder)
- [Example decorated input](#example-decorated-input)
- [Sanity Client mutation](#sanity-client-mutation)
- [Typed and validated responses](#typed-and-validated-responses)
- [Dynamic OG Image](#dynamic-og-image)
- [Other development choices](#other-development-choices)
- [Sanity Studio](#sanity-studio)
- [Deployment](#deployment)## Installation: As a Sanity project template
From the command line, install this project as a Sanity project template:
```sh
npm create sanity@latest -- --template https://github.com/SimeonGriggs/sanity-react-router-template
```You can create a new Sanity project or choose an existing one during the setup process. It will write these settings to a `.env` file and setup CORS origins and tokens as required.
## Installation: As a React Router template
From the command line, install this project as a React Router template:
```sh
npx create-react-router@latest --template SimeonGriggs/sanity-react-router-template
```This template comes with an init script, if you choose not to run it, you can run it later with:
```sh
npx react-router init
```This script should populate your `.env` file with the details of a new or existing Sanity project's ID and dataset name, as well as create a session secret and an API Token with Viewer permissions. If the init script has already been deleted, you can easily reset your `.env` file by running the following command:
```sh
npx sanity@latest init --env
```Then, start the development server:
```sh
npm run dev
```Now open the Studio at [localhost:5173/studio](http://localhost:5173/studio) and start authoring content!
### Seed the Studio with fake content
Your new Sanity project starts with no content. A script is included in this repo [using Faker to generate content](https://www.sanity.io/guides/create-fake-demo-content-with-sanity-cli) to start with.
> [!WARNING]
> This script will **delete** existing content in the dataset every time it is run. It is intended for use in a new dataset only.```sh
npx sanity@latest exec ./scripts/createData.ts --with-user-token
```## Includes
Useful Sanity examples with a light sprinkling of opinionated patterns
### Embedded Studio
Access to Sanity Studio v3 from within the React Router application itself. Now the whole Studio is a component, it lives at the `/studio` route.
### Visual Editing for interactive live preview inside Presentation
Powered by [Presentation](https://www.sanity.io/docs/presentation) and [@sanity/react-loader](https://www.sanity.io/docs/react-loader)
Authenticated users inside Sanity Studio can use the Presentation tool to browse through the website and target specific fields to edit - and see changes in real time.
The resource route (`/resource/preview`) used by Presentation will set a session token so that overlays will be visible even outside of Presentation.
### Pre-configured Studio
The Studio has been pre-configured with a basic "Record Collection" schema, as well as a basic Desk Structure to include live preview within a view pane.
### Portable Text component
Powered by [@portabletext/react](https://github.com/portabletext/react-portabletext)
This component allows for the customization and extension of how Portable Text is rendered within your app. The Rich Text field in Sanity is an array of objects. Content as data!
### Image URL builder
Powered by [@sanity/image-url](https://github.com/sanity-io/image-url)
The `` component has an example of how to generate a full Sanity CDN asset URL based on just the asset's ID. This is useful as we do not need to resolve the full image document in the query.
### Example decorated input
Powered by [@sanity/ui](https://www.sanity.io/ui)
Creating "decorated" inputs has never been easier than in Sanity Studio v3. `./app/sanity/components/Duration.tsx` is a 13-line example where a `number` field type to store duration as seconds can also be visualized in minutes. Minimal developer effort, maximum author impact.
### Sanity Client mutation
Powered by [@sanity/client](https://github.com/sanity-io/client)
Requires a token with **editor** permissions in `.env`. Clicking the like/dislike buttons on a Record's page will trigger a React Router action which will send a mutation to the document. This is an example of how user actions on the site may trigger changes on your Sanity dataset.
### Typed and validated responses
Powered by [Zod](https://zod.dev/)
The results of the Sanity query in `./app/routes/$slug.tsx` are parsed with a Zod validator. This ensures that content is always returned in the expected shape at **run time**, and auto-generates Types which are fed from the `loader` into `useLoaderData()`.
### Dynamic OG Image
The `record` type generates dynamic open graph images using the `~/routes/resource.og` resource route.
### Other development choices
- eslint and Prettier
- Tailwind CSS
- Tailwind Prose and Prettier plugins## Sanity Studio
Visit `https://localhost:5173/studio` in your React Router app. You will need to:
1. Rename `.env.template` to `.env`
2. Set the correct Project ID, Dataset Name and preferred API Version from a project in your [Sanity Manage](https://sanity.io/manage)
3. Add `http://localhost:5173` to the CORS settings on that project, with Allow Credentials privileges## Deployment
This React Router template is specifically configured for hosting on Vercel.
1. Check this repository into your own source control (like GitHub) and deploy to Vercel.