Skip to content

Commit

Permalink
Standardize Sanity template
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjonespizza committed Dec 17, 2024
1 parent daba197 commit ae1ef75
Show file tree
Hide file tree
Showing 31 changed files with 23,839 additions and 12,427 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Prettier

on:
push:
branches: [main]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read # for checkout

jobs:
run:
name: Can the code be prettier? 🤔
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: lts/*
- run: pnpm install --dev --ignore-scripts
- uses: actions/cache@v4
with:
path: node_modules/.cache/prettier/.prettier-cache
key: prettier-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('.prettierignore') }}-${{ hashFiles('package.json') }}
- run: pnpm format
- run: git restore .github/workflows pnpm-lock.yaml
- uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.ECOSPARK_APP_ID }}
private-key: ${{ secrets.ECOSPARK_APP_PRIVATE_KEY }}
- uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7
with:
body: I ran `pnpm format` 🧑‍💻
branch: actions/prettier
commit-message: 'chore(prettier): 🤖 ✨'
labels: 🤖 bot
sign-commits: true
title: 'chore(prettier): 🤖 ✨'
token: ${{ steps.generate-token.outputs.token }}
12 changes: 12 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Validate Template
on: push

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate Sanity Template
uses: sanity-io/[email protected]
with:
repository: ${{ github.repository }}
29 changes: 28 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
node_modules
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# env files
.env
.env.*
!.env.example

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
74 changes: 74 additions & 0 deletions BAK-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# A minimal Nuxt site with Sanity Studio

This starter uses [Nuxt](https://nuxt.com/) for the front end and [Sanity](https://www.sanity.io/) to handle its content.

## Featuring

- How to fetch content as data from [the Sanity Content Lake](https://www.sanity.io/docs/datastore)
- How to render block content with [Portable Text](https://www.sanity.io/docs/presenting-block-text)
- A [Sanity Studio](https://www.sanity.io/docs/sanity-studio) to create and edit content
- How to crop and render images with [Sanity Image URLs](https://www.sanity.io/docs/image-url)

> **Note**
>
> 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.
>
> 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.
## Prerequisities

- [Node.js](https://nodejs.org/en/) (v16.12 or later)
- [Sanity CLI](https://www.sanity.io/docs/getting-started-with-sanity-cli) (optional)

## Getting started

Run the following commands to prepare both applications, each step should be executed from the **root directory**:

1. Install dependencies.

```sh
pnpm install
```

2. Select or create a Sanity project and dataset, and output the details to a `.env` file.

```sh
cd studio && pnpm sanity init --env .env
```

3. [Generate a token](https://www.sanity.io/docs/http-auth#4c21d7b829fe) with read permissions for use in the next step.

```sh
pnpm sanity manage
```

4. Copy the example app `.env` file and populate it with the required values.

```sh
cd ..
cp ./app/.env.example ./app/.env
```

5. Start the development servers:

```sh
pnpm dev
```

- Your Nuxt app should now be running on [http://localhost:3000/](http://localhost:3000/).
- Your Studio should now be running on [http://localhost:3333/](http://localhost:3333/).

### Add content

1. Visit the Studio and create and publish a new `Post` document
2. Visit the App and refresh the page to see your content rendered on the page

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.

## Deployments

The `/app` and `/studio` folders are meant to be deployed separately.

Make sure that after `/app` is deployed the `.env` file in `/studio` is updated with its deployment URL under `SANITY_STUDIO_PREVIEW_URL`.

And `/app` has a `.env` file with `NUXT_SANITY_STUDIO_URL` that points to the Studio's deployment URL.
105 changes: 59 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,87 @@
# A minimal Nuxt site with Sanity Studio
# Clean Nuxt + Sanity app

This starter uses [Nuxt](https://nuxt.com/) for the front end and [Sanity](https://www.sanity.io/) to handle its content.
This template includes a [Nuxt](https://nuxt.com/) 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.

## Featuring
## Features

- How to fetch content as data from [the Sanity Content Lake](https://www.sanity.io/docs/datastore)
- How to render block content with [Portable Text](https://www.sanity.io/docs/presenting-block-text)
- A [Sanity Studio](https://www.sanity.io/docs/sanity-studio) to create and edit content
- How to crop and render images with [Sanity Image URLs](https://www.sanity.io/docs/image-url)
* Fetch content seamlessly with [Sanity Content Lake](https://www.sanity.io/docs/datastore).
* Render beautiful block content using [Portable Text](https://www.sanity.io/docs/presenting-block-text).
* Manage and create content with the intuitive [Sanity Studio](https://www.sanity.io/docs/sanity-studio).
* Live visual editing through [Sanity's Presentation tools](https://www.sanity.io/docs/presentation).
* Advanced image cropping and rendering via [Sanity Image URLs](https://www.sanity.io/docs/image-url).

> **Note**
>
> 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.
>
> 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.
## Demo

## Prerequisities
https://sanity-template-nuxt-clean.sanity.build

- [Node.js](https://nodejs.org/en/) (v16.12 or later)
- [Sanity CLI](https://www.sanity.io/docs/getting-started-with-sanity-cli) (optional)
## Getting Started

## Getting started
### Install the template

Run the following commands to prepare both applications, each step should be executed from the **root directory**:
#### 1. Initialize template with Sanity CLI

1. Install dependencies.
Run the command in your Terminal to initialize this template on your local computer.

```sh
pnpm install
See the documentation if you are [having issues with the CLI](https://www.sanity.io/help/cli-errors).

```shell
npm create sanity@latest -- --template sanity-io/sanity-template-nuxt-clean
```

2. Select or create a Sanity project and dataset, and output the details to a `.env` file.
#### 2. Run the application and Sanity Studio

Navigate to the template directory using `cd <your app name>`, and start the development servers by running the following command

```sh
cd studio && pnpm sanity init --env .env
```shell
npm run dev
```

3. [Generate a token](https://www.sanity.io/docs/http-auth#4c21d7b829fe) with read permissions for use in the next step.
#### 3. Open the app and sign in to the Studio

```sh
pnpm sanity manage
```
Open the Nuxt app running locally in your browser on [http://localhost:3000](http://localhost:3000).

4. Copy the example app `.env` file and populate it with the required values.
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.

```sh
cd ..
cp ./app/.env.example ./app/.env
```
### Adding content with Sanity

5. Start the development servers:
#### 1. Publish your first document
The template comes pre-defined with a schema containing a `Post` document type.

```sh
pnpm dev
```
From the Studio, click "+ Create" and select the `Post` document type. Go ahead and create and publish the document.

Your content should now appear in your Nuxt app ([http://localhost:3000](http://localhost:3000)) as well as in the Studio on the "Presentation" Tab

- Your Nuxt app should now be running on [http://localhost:3000/](http://localhost:3000/).
- Your Studio should now be running on [http://localhost:3333/](http://localhost:3333/).
#### 2. Extending the Sanity schema
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.

### Deploying your application and inviting editors

#### 1. Deploy Sanity Studio
Your Nuxt frontend (`/nuxt-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.

Back in your Studio directory (`/studio`), run the following command to deploy your Sanity Studio.

```shell
npx sanity deploy
```

### Add content
#### 2. Deploy Nuxt app to Vercel

1. Visit the Studio and create and publish a new `Post` document
2. Visit the App and refresh the page to see your content rendered on the page
You have the freedom to deploy your Nuxt app to your hosting provider of choice. With Vercel and GitHub being a popular choice, we'll cover the basics of that approach.

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.
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).
2. Create a new Vercel project and connect it to your Github repository.
3. Set the `Root Directory` to your Nuxt app.
4. Configure your Environment Variables.

## Deployments
#### 3. Invite a collaborator
Now that you’ve deployed your Nuxt 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"

The `/app` and `/studio` folders are meant to be deployed separately.
They will be able to access the deployed Studio, where you can collaborate together on creating content.

Make sure that after `/app` is deployed the `.env` file in `/studio` is updated with its deployment URL under `SANITY_STUDIO_PREVIEW_URL`.

And `/app` has a `.env` file with `NUXT_SANITY_STUDIO_URL` that points to the Studio's deployment URL.
## Resources
- [Sanity documentation](https://www.sanity.io/docs)
- [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction)
- [Join the Sanity Community](https://slack.sanity.io)
- [Learn Sanity](https://www.sanity.io/learn)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ae1ef75

Please sign in to comment.