Skip to content

Commit

Permalink
set up sanity cms inside of project
Browse files Browse the repository at this point in the history
pnpm create sanity@latest -- --template clean --create-project "mueller" --dataset production
  • Loading branch information
bozzhik committed Nov 18, 2024
1 parent a32c25f commit 0fda916
Show file tree
Hide file tree
Showing 13 changed files with 8,374 additions and 1,302 deletions.
16 changes: 12 additions & 4 deletions next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import type { NextConfig } from "next";
import type {NextConfig} from 'next'

const nextConfig: NextConfig = {
/* config options here */
};
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn.sanity.io',
},
],
},
// ...other config settings
}

export default nextConfig;
export default nextConfig
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
"lint": "next lint"
},
"dependencies": {
"@sanity/image-url": "1",
"@sanity/vision": "3",
"gsap": "^3.12.5",
"next": "15.0.3",
"next-sanity": "9",
"react": "19.0.0-rc-66855b96-20241106",
"react-dom": "19.0.0-rc-66855b96-20241106"
"react-dom": "19.0.0-rc-66855b96-20241106",
"sanity": "3",
"styled-components": "6"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
9,525 changes: 8,228 additions & 1,297 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions sanity.cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This configuration file lets you run `$ sanity [command]` in this folder
* Go to https://www.sanity.io/docs/cli to learn more.
**/
import { defineCliConfig } from 'sanity/cli'

const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET

export default defineCliConfig({ api: { projectId, dataset } })
28 changes: 28 additions & 0 deletions sanity.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client'

/**
* This configuration is used to for the Sanity Studio that’s mounted on the `\src\app\studio\[[...tool]]\page.tsx` route
*/

import {visionTool} from '@sanity/vision'
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'

// Go to https://www.sanity.io/docs/api-versioning to learn how API versioning works
import {apiVersion, dataset, projectId} from './src/sanity/env'
import {schema} from './src/sanity/schemaTypes'
import {structure} from './src/sanity/structure'

export default defineConfig({
basePath: '/studio',
projectId,
dataset,
// Add and edit the content schema in the './sanity/schemaTypes' folder
schema,
plugins: [
structureTool({structure}),
// Vision is for querying with GROQ from inside the Studio
// https://www.sanity.io/docs/the-vision-plugin
visionTool({defaultApiVersion: apiVersion}),
],
})
5 changes: 5 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

#sanity {
position: relative;
z-index: 9999;
}
19 changes: 19 additions & 0 deletions src/app/studio/[[...tool]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This route is responsible for the built-in authoring environment using Sanity Studio.
* All routes under your studio path is handled by this file using Next.js' catch-all routes:
* https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes
*
* You can learn more about the next-sanity package here:
* https://github.com/sanity-io/next-sanity
*/

import { NextStudio } from 'next-sanity/studio'
import config from '../../../../sanity.config'

export const dynamic = 'force-static'

export { metadata, viewport } from 'next-sanity/studio'

export default function StudioPage() {
return <NextStudio config={config} />
}
20 changes: 20 additions & 0 deletions src/sanity/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const apiVersion =
process.env.NEXT_PUBLIC_SANITY_API_VERSION || '2024-11-17'

export const dataset = assertValue(
process.env.NEXT_PUBLIC_SANITY_DATASET,
'Missing environment variable: NEXT_PUBLIC_SANITY_DATASET'
)

export const projectId = assertValue(
process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
'Missing environment variable: NEXT_PUBLIC_SANITY_PROJECT_ID'
)

function assertValue<T>(v: T | undefined, errorMessage: string): T {
if (v === undefined) {
throw new Error(errorMessage)
}

return v
}
10 changes: 10 additions & 0 deletions src/sanity/lib/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createClient } from 'next-sanity'

import { apiVersion, dataset, projectId } from '../env'

export const client = createClient({
projectId,
dataset,
apiVersion,
useCdn: true, // Set to false if statically generating pages, using ISR or tag-based revalidation
})
11 changes: 11 additions & 0 deletions src/sanity/lib/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import createImageUrlBuilder from '@sanity/image-url'
import { SanityImageSource } from "@sanity/image-url/lib/types/types";

import { dataset, projectId } from '../env'

// https://www.sanity.io/docs/image-url
const builder = createImageUrlBuilder({ projectId, dataset })

export const urlFor = (source: SanityImageSource) => {
return builder.image(source)
}
13 changes: 13 additions & 0 deletions src/sanity/lib/live.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Querying with "sanityFetch" will keep content automatically updated
// Before using it, import and render "<SanityLive />" in your layout, see
// https://github.com/sanity-io/next-sanity#live-content-api for more information.
import { defineLive } from "next-sanity";
import { client } from './client'

export const { sanityFetch, SanityLive } = defineLive({
client: client.withConfig({
// Live content is currently only available on the experimental API
// https://www.sanity.io/docs/api-versioning
apiVersion: 'vX'
})
});
5 changes: 5 additions & 0 deletions src/sanity/schemaTypes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { type SchemaTypeDefinition } from 'sanity'

export const schema: { types: SchemaTypeDefinition[] } = {
types: [],
}
7 changes: 7 additions & 0 deletions src/sanity/structure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type {StructureResolver} from 'sanity/structure'

// https://www.sanity.io/docs/structure-builder-cheat-sheet
export const structure: StructureResolver = (S) =>
S.list()
.title('Content')
.items(S.documentTypeListItems())

0 comments on commit 0fda916

Please sign in to comment.