Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8418d72

Browse files
authoredJan 7, 2025··
Create a script in the root package.json for importing sample data (#102)
* Add script for importing sample data
1 parent 8ae2218 commit 8418d72

File tree

5 files changed

+94
-152
lines changed

5 files changed

+94
-152
lines changed
 

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ From the Studio, click "+ Create" and select the `Post` document type. Go ahead
5757

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

60-
#### 2. Import Demo Data (optional)
60+
#### 2. Import Sample Data (optional)
6161

62-
You may want to start with some sample content and we've got you covered. Run this command from `/studio` directory to import the provided dataset (demoData.tar.gz) into your Sanity project. This step is optional but can be helpful for getting started quickly.
62+
You may want to start with some sample content and we've got you covered. Run this command from the root of your project to import the provided dataset (sample-data.tar.gz) into your Sanity project. This step is optional but can be helpful for getting started quickly.
6363

6464
```shell
65-
npx sanity dataset import demoData.tar.gz <your dataset name>
65+
npm run import-sample-data
6666
```
6767

6868
#### 3. Extending the Sanity schema

‎nextjs-app/sanity.types.ts

+89-148
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,11 @@ export type Page = {
176176
slug: Slug;
177177
heading: string;
178178
subheading?: string;
179-
pageBuilder?: Array<
180-
| ({
181-
_key: string;
182-
} & CallToAction)
183-
| ({
184-
_key: string;
185-
} & InfoSection)
186-
>;
179+
pageBuilder?: Array<{
180+
_key: string;
181+
} & CallToAction | {
182+
_key: string;
183+
} & InfoSection>;
187184
};
188185

189186
export type Post = {
@@ -353,21 +350,17 @@ export type SanityAssistInstructionTask = {
353350

354351
export type SanityAssistTaskStatus = {
355352
_type: "sanity.assist.task.status";
356-
tasks?: Array<
357-
{
358-
_key: string;
359-
} & SanityAssistInstructionTask
360-
>;
353+
tasks?: Array<{
354+
_key: string;
355+
} & SanityAssistInstructionTask>;
361356
};
362357

363358
export type SanityAssistSchemaTypeAnnotations = {
364359
_type: "sanity.assist.schemaType.annotations";
365360
title?: string;
366-
fields?: Array<
367-
{
368-
_key: string;
369-
} & SanityAssistSchemaTypeField
370-
>;
361+
fields?: Array<{
362+
_key: string;
363+
} & SanityAssistSchemaTypeField>;
371364
};
372365

373366
export type SanityAssistOutputType = {
@@ -420,23 +413,18 @@ export type SanityAssistInstructionUserInput = {
420413
};
421414

422415
export type SanityAssistInstructionPrompt = Array<{
423-
children?: Array<
424-
| {
425-
marks?: Array<string>;
426-
text?: string;
427-
_type: "span";
428-
_key: string;
429-
}
430-
| ({
431-
_key: string;
432-
} & SanityAssistInstructionFieldRef)
433-
| ({
434-
_key: string;
435-
} & SanityAssistInstructionContext)
436-
| ({
437-
_key: string;
438-
} & SanityAssistInstructionUserInput)
439-
>;
416+
children?: Array<{
417+
marks?: Array<string>;
418+
text?: string;
419+
_type: "span";
420+
_key: string;
421+
} | {
422+
_key: string;
423+
} & SanityAssistInstructionFieldRef | {
424+
_key: string;
425+
} & SanityAssistInstructionContext | {
426+
_key: string;
427+
} & SanityAssistInstructionUserInput>;
440428
style?: "normal";
441429
listItem?: never;
442430
markDefs?: null;
@@ -457,58 +445,22 @@ export type SanityAssistInstruction = {
457445
title?: string;
458446
userId?: string;
459447
createdById?: string;
460-
output?: Array<
461-
| ({
462-
_key: string;
463-
} & SanityAssistOutputField)
464-
| ({
465-
_key: string;
466-
} & SanityAssistOutputType)
467-
>;
448+
output?: Array<{
449+
_key: string;
450+
} & SanityAssistOutputField | {
451+
_key: string;
452+
} & SanityAssistOutputType>;
468453
};
469454

470455
export type SanityAssistSchemaTypeField = {
471456
_type: "sanity.assist.schemaType.field";
472457
path?: string;
473-
instructions?: Array<
474-
{
475-
_key: string;
476-
} & SanityAssistInstruction
477-
>;
458+
instructions?: Array<{
459+
_key: string;
460+
} & SanityAssistInstruction>;
478461
};
479462

480-
export type AllSanitySchemaTypes =
481-
| SanityImagePaletteSwatch
482-
| SanityImagePalette
483-
| SanityImageDimensions
484-
| SanityFileAsset
485-
| Geopoint
486-
| CallToAction
487-
| Link
488-
| InfoSection
489-
| BlockContent
490-
| Page
491-
| Post
492-
| Person
493-
| Slug
494-
| Settings
495-
| SanityImageCrop
496-
| SanityImageHotspot
497-
| SanityImageAsset
498-
| SanityAssetSourceData
499-
| SanityImageMetadata
500-
| SanityAssistInstructionTask
501-
| SanityAssistTaskStatus
502-
| SanityAssistSchemaTypeAnnotations
503-
| SanityAssistOutputType
504-
| SanityAssistOutputField
505-
| SanityAssistInstructionContext
506-
| AssistInstructionContext
507-
| SanityAssistInstructionUserInput
508-
| SanityAssistInstructionPrompt
509-
| SanityAssistInstructionFieldRef
510-
| SanityAssistInstruction
511-
| SanityAssistSchemaTypeField;
463+
export type AllSanitySchemaTypes = SanityImagePaletteSwatch | SanityImagePalette | SanityImageDimensions | SanityFileAsset | Geopoint | CallToAction | Link | InfoSection | BlockContent | Page | Post | Person | Slug | Settings | SanityImageCrop | SanityImageHotspot | SanityImageAsset | SanityAssetSourceData | SanityImageMetadata | SanityAssistInstructionTask | SanityAssistTaskStatus | SanityAssistSchemaTypeAnnotations | SanityAssistOutputType | SanityAssistOutputField | SanityAssistInstructionContext | AssistInstructionContext | SanityAssistInstructionUserInput | SanityAssistInstructionPrompt | SanityAssistInstructionFieldRef | SanityAssistInstruction | SanityAssistSchemaTypeField;
512464
export declare const internalGroqTypeReferenceTo: unique symbol;
513465
// Source: ./sanity/lib/queries.ts
514466
// Variable: settingsQuery
@@ -561,69 +513,58 @@ export type GetPageQueryResult = {
561513
slug: Slug;
562514
heading: string;
563515
subheading: string | null;
564-
pageBuilder: Array<
565-
| {
566-
_key: string;
567-
_type: "callToAction";
568-
heading: string;
516+
pageBuilder: Array<{
517+
_key: string;
518+
_type: "callToAction";
519+
heading: string;
520+
text?: string;
521+
buttonText?: string;
522+
link: {
523+
_type: "link";
524+
linkType?: "href" | "page" | "post";
525+
href?: string;
526+
page: string | null;
527+
post: string | null;
528+
openInNewTab?: boolean;
529+
} | null;
530+
} | {
531+
_key: string;
532+
_type: "infoSection";
533+
heading?: string;
534+
subheading?: string;
535+
content?: Array<{
536+
children?: Array<{
537+
marks?: Array<string>;
569538
text?: string;
570-
buttonText?: string;
571-
link: {
572-
_type: "link";
573-
linkType?: "href" | "page" | "post";
574-
href?: string;
575-
page: string | null;
576-
post: string | null;
577-
openInNewTab?: boolean;
578-
} | null;
579-
}
580-
| {
539+
_type: "span";
540+
_key: string;
541+
}>;
542+
style?: "blockquote" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "normal";
543+
listItem?: "bullet" | "number";
544+
markDefs?: Array<{
545+
linkType?: "href" | "page" | "post";
546+
href?: string;
547+
page?: {
548+
_ref: string;
549+
_type: "reference";
550+
_weak?: boolean;
551+
[internalGroqTypeReferenceTo]?: "page";
552+
};
553+
post?: {
554+
_ref: string;
555+
_type: "reference";
556+
_weak?: boolean;
557+
[internalGroqTypeReferenceTo]?: "post";
558+
};
559+
openInNewTab?: boolean;
560+
_type: "link";
581561
_key: string;
582-
_type: "infoSection";
583-
heading?: string;
584-
subheading?: string;
585-
content?: Array<{
586-
children?: Array<{
587-
marks?: Array<string>;
588-
text?: string;
589-
_type: "span";
590-
_key: string;
591-
}>;
592-
style?:
593-
| "blockquote"
594-
| "h1"
595-
| "h2"
596-
| "h3"
597-
| "h4"
598-
| "h5"
599-
| "h6"
600-
| "normal";
601-
listItem?: "bullet" | "number";
602-
markDefs?: Array<{
603-
linkType?: "href" | "page" | "post";
604-
href?: string;
605-
page?: {
606-
_ref: string;
607-
_type: "reference";
608-
_weak?: boolean;
609-
[internalGroqTypeReferenceTo]?: "page";
610-
};
611-
post?: {
612-
_ref: string;
613-
_type: "reference";
614-
_weak?: boolean;
615-
[internalGroqTypeReferenceTo]?: "post";
616-
};
617-
openInNewTab?: boolean;
618-
_type: "link";
619-
_key: string;
620-
}>;
621-
level?: number;
622-
_type: "block";
623-
_key: string;
624-
}>;
625-
}
626-
> | null;
562+
}>;
563+
level?: number;
564+
_type: "block";
565+
_key: string;
566+
}>;
567+
}> | null;
627568
} | null;
628569
// Variable: allPostsQuery
629570
// Query: *[_type == "post" && defined(slug.current)] | order(date desc, _updatedAt desc) { _id, "status": select(_originalId in path("drafts.**") => "draft", "published"), "title": coalesce(title, "Untitled"), "slug": slug.current, excerpt, coverImage, "date": coalesce(date, _updatedAt), "author": author->{firstName, lastName, picture}, }
@@ -787,12 +728,12 @@ export type PagesSlugsResult = Array<{
787728
import "@sanity/client";
788729
declare module "@sanity/client" {
789730
interface SanityQueries {
790-
'*[_type == "settings"][0]': SettingsQueryResult;
791-
'\n *[_type == \'page\' && slug.current == $slug][0]{\n _id,\n _type,\n name,\n slug,\n heading,\n subheading,\n "pageBuilder": pageBuilder[]{\n ...,\n _type == "callToAction" => {\n ...,\n \n link {\n ...,\n _type == "link" => {\n "page": page->slug.current,\n "post": post->slug.current\n }\n }\n,\n }\n },\n }\n': GetPageQueryResult;
792-
'\n *[_type == "post" && defined(slug.current)] | order(date desc, _updatedAt desc) {\n \n _id,\n "status": select(_originalId in path("drafts.**") => "draft", "published"),\n "title": coalesce(title, "Untitled"),\n "slug": slug.current,\n excerpt,\n coverImage,\n "date": coalesce(date, _updatedAt),\n "author": author->{firstName, lastName, picture},\n\n }\n': AllPostsQueryResult;
793-
'\n *[_type == "post" && _id != $skip && defined(slug.current)] | order(date desc, _updatedAt desc) [0...$limit] {\n \n _id,\n "status": select(_originalId in path("drafts.**") => "draft", "published"),\n "title": coalesce(title, "Untitled"),\n "slug": slug.current,\n excerpt,\n coverImage,\n "date": coalesce(date, _updatedAt),\n "author": author->{firstName, lastName, picture},\n\n }\n': MorePostsQueryResult;
794-
'\n *[_type == "post" && slug.current == $slug] [0] {\n content[]{\n ...,\n markDefs[]{\n ...,\n \n link {\n ...,\n _type == "link" => {\n "page": page->slug.current,\n "post": post->slug.current\n }\n }\n\n }\n },\n \n _id,\n "status": select(_originalId in path("drafts.**") => "draft", "published"),\n "title": coalesce(title, "Untitled"),\n "slug": slug.current,\n excerpt,\n coverImage,\n "date": coalesce(date, _updatedAt),\n "author": author->{firstName, lastName, picture},\n\n }\n': PostQueryResult;
795-
'\n *[_type == "post" && defined(slug.current)]\n {"slug": slug.current}\n': PostPagesSlugsResult;
796-
'\n *[_type == "page" && defined(slug.current)]\n {"slug": slug.current}\n': PagesSlugsResult;
731+
"*[_type == \"settings\"][0]": SettingsQueryResult;
732+
"\n *[_type == 'page' && slug.current == $slug][0]{\n _id,\n _type,\n name,\n slug,\n heading,\n subheading,\n \"pageBuilder\": pageBuilder[]{\n ...,\n _type == \"callToAction\" => {\n ...,\n \n link {\n ...,\n _type == \"link\" => {\n \"page\": page->slug.current,\n \"post\": post->slug.current\n }\n }\n,\n }\n },\n }\n": GetPageQueryResult;
733+
"\n *[_type == \"post\" && defined(slug.current)] | order(date desc, _updatedAt desc) {\n \n _id,\n \"status\": select(_originalId in path(\"drafts.**\") => \"draft\", \"published\"),\n \"title\": coalesce(title, \"Untitled\"),\n \"slug\": slug.current,\n excerpt,\n coverImage,\n \"date\": coalesce(date, _updatedAt),\n \"author\": author->{firstName, lastName, picture},\n\n }\n": AllPostsQueryResult;
734+
"\n *[_type == \"post\" && _id != $skip && defined(slug.current)] | order(date desc, _updatedAt desc) [0...$limit] {\n \n _id,\n \"status\": select(_originalId in path(\"drafts.**\") => \"draft\", \"published\"),\n \"title\": coalesce(title, \"Untitled\"),\n \"slug\": slug.current,\n excerpt,\n coverImage,\n \"date\": coalesce(date, _updatedAt),\n \"author\": author->{firstName, lastName, picture},\n\n }\n": MorePostsQueryResult;
735+
"\n *[_type == \"post\" && slug.current == $slug] [0] {\n content[]{\n ...,\n markDefs[]{\n ...,\n \n link {\n ...,\n _type == \"link\" => {\n \"page\": page->slug.current,\n \"post\": post->slug.current\n }\n }\n\n }\n },\n \n _id,\n \"status\": select(_originalId in path(\"drafts.**\") => \"draft\", \"published\"),\n \"title\": coalesce(title, \"Untitled\"),\n \"slug\": slug.current,\n excerpt,\n coverImage,\n \"date\": coalesce(date, _updatedAt),\n \"author\": author->{firstName, lastName, picture},\n\n }\n": PostQueryResult;
736+
"\n *[_type == \"post\" && defined(slug.current)]\n {\"slug\": slug.current}\n": PostPagesSlugsResult;
737+
"\n *[_type == \"page\" && defined(slug.current)]\n {\"slug\": slug.current}\n": PagesSlugsResult;
797738
}
798739
}

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "sanity-template-nextjs-clean",
33
"description": "Next.js + Sanity: A Powerful Website Starter with Real-time Visual Editing",
44
"scripts": {
5-
"dev": "concurrently \"npm run dev --workspace=nextjs-app\" \"npm run dev --workspace=studio\""
5+
"dev": "concurrently \"npm run dev --workspace=nextjs-app\" \"npm run dev --workspace=studio\"",
6+
"import-sample-data": "cd studio && sanity dataset import sample-data.tar.gz --replace"
67
},
78
"keywords": [
89
"Sanity",

‎studio/demoData.tar.gz

-4.67 MB
Binary file not shown.

‎studio/sample-data.tar.gz

4.67 MB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.