Skip to content

Commit

Permalink
chore: add new example app with visual editing enabled (#188)
Browse files Browse the repository at this point in the history
The example app uses a new movies Sanity project so we can freely play around
with the data.
  • Loading branch information
christianhg authored May 30, 2024
1 parent 9f19311 commit 6cdb0b2
Show file tree
Hide file tree
Showing 27 changed files with 1,348 additions and 45 deletions.
4 changes: 2 additions & 2 deletions apps/example-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"astro": "astro",
"build": "astro build",
"clean": "rimraf .astro && rimraf .turbo && rimraf .vercel && rimraf node_modules",
"dev": "astro dev",
"dev": "astro dev --port 4323",
"preview": "astro preview",
"start": "astro dev"
"start": "astro dev --port 4323"
},
"dependencies": {
"@astro-community/astro-embed-youtube": "^0.5.2",
Expand Down
4 changes: 2 additions & 2 deletions apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"astro": "astro",
"build": "astro build",
"clean": "rimraf .astro rimraf dist && rimraf .turbo && rimraf node_modules",
"dev": "astro dev",
"dev": "astro dev --port 4322",
"preview": "astro preview",
"start": "astro dev"
"start": "astro dev --port 4322"
},
"dependencies": {
"@astro-community/astro-embed-youtube": "^0.5.2",
Expand Down
26 changes: 26 additions & 0 deletions apps/movies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

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


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# jetbrains setting folder
.idea/
.vercel
.env*.local
4 changes: 4 additions & 0 deletions apps/movies/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}
11 changes: 11 additions & 0 deletions apps/movies/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
1 change: 1 addition & 0 deletions apps/movies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Movies Example App
23 changes: 23 additions & 0 deletions apps/movies/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {defineConfig} from 'astro/config'

import react from '@astrojs/react'
import vercel from '@astrojs/vercel/serverless'
import sanity from '@sanity/astro'

// https://astro.build/config
export default defineConfig({
integrations: [
sanity({
projectId: '4j2qnyob',
dataset: 'production',
useCdn: true,
studioBasePath: '/admin',
stega: {
studioUrl: '/admin',
},
}),
react(),
],
output: 'server',
adapter: vercel(),
})
29 changes: 29 additions & 0 deletions apps/movies/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "movies",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"astro": "astro",
"build": "astro check && astro build",
"dev": "astro dev --port 4321",
"preview": "astro preview",
"start": "astro dev --port 4321"
},
"dependencies": {
"@astrojs/check": "^0.7.0",
"@astrojs/react": "^3.4.0",
"@astrojs/vercel": "^7.3.4",
"@sanity/astro": "workspace:^",
"@sanity/client": "^6.19.1",
"@sanity/visual-editing": "^2.1.3",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"astro": "^4.9.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.2.1",
"sanity": "^3.44.0",
"typescript": "^5.4.5"
}
}
9 changes: 9 additions & 0 deletions apps/movies/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions apps/movies/sanity.cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {defineCliConfig} from 'sanity/cli'

export default defineCliConfig({
api: {
projectId: '4j2qnyob',
dataset: 'production',
},
})
27 changes: 27 additions & 0 deletions apps/movies/sanity.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {schemaTypes} from './schemaTypes'
import {presentationTool} from 'sanity/presentation'

export default defineConfig({
name: 'default',
title: 'sanity-astro-movies',

projectId: '4j2qnyob',
dataset: 'production',

plugins: [
presentationTool({
previewUrl: process.env.VERCEL_BRANCH_URL
? `https://${process.env.VERCEL_BRANCH_URL}`
: process.env.VERCEL_PROJECT_PRODUCTION_URL
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
: 'http://localhost:4321',
}),
structureTool(),
],

schema: {
types: schemaTypes,
},
})
67 changes: 67 additions & 0 deletions apps/movies/schemaTypes/blockContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {defineArrayMember, defineType} from 'sanity'

/**
* This is the schema definition for the rich text fields used for
* for this blog studio. When you import it in schemas.js it can be
* reused in other parts of the studio with:
* {
* name: 'someName',
* title: 'Some title',
* type: 'blockContent'
* }
*/
export default defineType({
title: 'Block Content',
name: 'blockContent',
type: 'array',
of: [
defineArrayMember({
title: 'Block',
type: 'block',
// Styles let you set what your user can mark up blocks with. These
// correspond with HTML tags, but you can set any title or value
// you want and decide how you want to deal with it where you want to
// use your content.
styles: [
{title: 'Normal', value: 'normal'},
{title: 'H1', value: 'h1'},
{title: 'H2', value: 'h2'},
{title: 'H3', value: 'h3'},
{title: 'H4', value: 'h4'},
{title: 'Quote', value: 'blockquote'},
],
lists: [{title: 'Bullet', value: 'bullet'}],
// Marks let you mark up inline text in the block editor.
marks: {
// Decorators usually describe a single property – e.g. a typographic
// preference or highlighting by editors.
decorators: [
{title: 'Strong', value: 'strong'},
{title: 'Emphasis', value: 'em'},
],
// Annotations can be any object structure – e.g. a link or a footnote.
annotations: [
{
title: 'URL',
name: 'link',
type: 'object',
fields: [
{
title: 'URL',
name: 'href',
type: 'url',
},
],
},
],
},
}),
// You can add additional types here. Note that you can't use
// primitive types such as 'string' and 'number' in the same array
// as a block type.
defineArrayMember({
type: 'image',
options: {hotspot: true},
}),
],
})
37 changes: 37 additions & 0 deletions apps/movies/schemaTypes/castMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {defineField, defineType} from 'sanity'

export default defineType({
name: 'castMember',
title: 'Cast Member',
type: 'object',
fields: [
defineField({
name: 'characterName',
title: 'Character Name',
type: 'string',
}),
defineField({
name: 'person',
title: 'Actor',
type: 'reference',
to: [{type: 'person'}],
}),
defineField({
name: 'externalId',
title: 'External ID',
type: 'number',
}),
defineField({
name: 'externalCreditId',
title: 'External Credit ID',
type: 'string',
}),
],
preview: {
select: {
subtitle: 'characterName',
title: 'person.name',
media: 'person.image',
},
},
})
52 changes: 52 additions & 0 deletions apps/movies/schemaTypes/crewMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// @ts-check
import {defineField, defineType} from 'sanity'

export default defineType({
name: 'crewMember',
title: 'Crew Member',
type: 'object',
fields: [
defineField({
name: 'department',
title: 'Department',
type: 'string',
}),
defineField({
name: 'job',
title: 'Job',
type: 'string',
}),
defineField({
name: 'person',
title: 'Person',
type: 'reference',
to: [{type: 'person'}],
}),
defineField({
name: 'externalId',
title: 'External ID',
type: 'number',
}),
defineField({
name: 'externalCreditId',
title: 'External Credit ID',
type: 'string',
}),
],
preview: {
select: {
name: 'person.name',
job: 'job',
department: 'department',
media: 'person.image',
},
prepare(selection) {
const {name, job, department, media} = selection
return {
title: name,
subtitle: `${job} [${department}]`,
media,
}
},
},
})
22 changes: 22 additions & 0 deletions apps/movies/schemaTypes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import blockContent from './blockContent'
import crewMember from './crewMember'
import castMember from './castMember'
import movie from './movie'
import person from './person'
import screening from './screening'
import plotSummary from './plotSummary'
import plotSummaries from './plotSummaries'

export const schemaTypes = [
// Document types
movie,
person,
screening,

// Other types
blockContent,
plotSummary,
plotSummaries,
castMember,
crewMember,
]
Loading

0 comments on commit 6cdb0b2

Please sign in to comment.