Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: embellish nextjs blog starter #7258

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,14 @@ export default async function initSanity(
}
const {chosen} = await getPackageManagerChoice(workDir, {interactive: false})
trace.log({step: 'selectPackageManager', selectedOption: chosen})
const packages = ['@sanity/vision@3', 'sanity@3', '@sanity/image-url@1', 'styled-components@6']
if (templateToUse === 'blog') {
packages.push('@sanity/icons')
}
await installNewPackages(
{
packageManager: chosen,
packages: ['@sanity/vision@3', 'sanity@3', '@sanity/image-url@1', 'styled-components@6'],
packages,
},
{
output: context.output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ export function promptForNextTemplate(prompt: CliPrompter): Promise<'clean' | 'b
message: 'Select project template to use',
type: 'list',
choices: [
{
value: 'clean',
name: 'Clean project with no predefined schema types',
},
{
value: 'blog',
name: 'Blog (schema)',
},
{
value: 'clean',
name: 'Clean project with no predefined schema types',
},
],
default: 'clean',
default: 'blog',
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ 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 ${hasSrcFolder ? "'./src/sanity/env'" : "'./sanity/env'"}
import {schema} from ${hasSrcFolder ? "'./src/sanity/schema'" : "'./sanity/schema'"}
import {schema} from ${hasSrcFolder ? "'./src/sanity/schemaTypes'" : "'./sanity/schemaTypes'"}
import {structure} from ${hasSrcFolder ? "'./src/sanity/structure'" : "'./sanity/structure'"}
SimeonGriggs marked this conversation as resolved.
Show resolved Hide resolved

export default defineConfig({
basePath: ':basePath:',
projectId,
dataset,
// Add and edit the content schema in the './sanity/schema' folder
// Add and edit the content schema in the './sanity/schemaTypes' folder
schema,
plugins: [
structureTool(),
// Vision is a tool that lets you query your content with GROQ in the studio
structureTool({structure}),
// Vision is for querying with GROQ from inside the Studio
// https://www.sanity.io/docs/the-vision-plugin
visionTool({defaultApiVersion: apiVersion}),
],
Expand Down Expand Up @@ -59,7 +60,8 @@ export { metadata, viewport } from 'next-sanity/studio'

export default function StudioPage() {
return <NextStudio config={config} />
}`
}
`

// Format today's date like YYYY-MM-DD
const envTS = `export const apiVersion =
Expand Down Expand Up @@ -103,6 +105,54 @@ const schemaJS = `export const schema = {
}
`

const blogStructureTS = `import type {StructureResolver} from 'sanity/structure'

// https://www.sanity.io/docs/structure-builder-cheat-sheet
export const structure: StructureResolver = (S) =>
S.list()
.title('Blog')
.items([
S.documentTypeListItem('post').title('Posts'),
S.documentTypeListItem('category').title('Categories'),
S.documentTypeListItem('author').title('Authors'),
S.divider(),
...S.documentTypeListItems().filter(
(item) => item.getId() && !['post', 'category', 'author'].includes(item.getId()!),
),
])
`

const blogStructureJS = `// https://www.sanity.io/docs/structure-builder-cheat-sheet
export const structure = (S) =>
S.list()
.title('Blog')
.items([
S.documentTypeListItem('post').title('Posts'),
S.documentTypeListItem('category').title('Categories'),
S.documentTypeListItem('author').title('Authors'),
S.divider(),
...S.documentTypeListItems().filter(
(item) => item.getId() && !['post', 'category', 'author'].includes(item.getId()),
),
])
`

const structureTS = `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())
`

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

const client = `import { createClient } from 'next-sanity'

import { apiVersion, dataset, projectId } from '../env'
Expand Down Expand Up @@ -146,26 +196,26 @@ export const sanityFolder = (
useTypeScript: boolean,
template?: 'clean' | 'blog',
): FolderStructure => {
const isBlogTemplate = template === 'blog'

// Files used in both templates
const structure: FolderStructure = {
// eslint-disable-next-line no-nested-ternary
'schema.': useTypeScript
? isBlogTemplate
? blogSchemaTS
: schemaTS
: isBlogTemplate
? blogSchemaJS
: schemaJS,
'env.': useTypeScript ? envTS : envJS,
'lib': {
'client.': client,
'image.': useTypeScript ? imageTS : imageJS,
},
}

if (isBlogTemplate) {
structure.schemaTypes = blogSchemaFolder(useTypeScript)
if (template === 'blog') {
structure.schemaTypes = {
...blogSchemaFolder,
'index.': useTypeScript ? blogSchemaTS : blogSchemaJS,
}
structure['structure.'] = useTypeScript ? blogStructureTS : blogStructureJS
} else {
structure.schemaTypes = {
'index.': useTypeScript ? schemaTS : schemaJS,
}
structure['structure.'] = useTypeScript ? structureTS : structureJS
}

return structure
Expand Down
Loading
Loading