mirror of
https://github.com/vercel/commerce.git
synced 2025-07-24 10:41:23 +00:00
Added search pages to sanity and storefront
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
/**
|
||||
* Desk structure overrides
|
||||
*/
|
||||
import {ListItemBuilder, StructureResolver} from 'sanity/desk'
|
||||
import { ListItemBuilder, StructureResolver } from 'sanity/desk'
|
||||
import blurbs from './blurb-structure'
|
||||
import categories from './category-structure'
|
||||
import home from './home-structure'
|
||||
import navigation from './navigation-structure'
|
||||
import pages from './page-structure'
|
||||
import products from './product-structure'
|
||||
import settings from './settings-structure'
|
||||
import blurbs from './blurb-structure'
|
||||
import search from './search-structure'
|
||||
import sections from './section-structure'
|
||||
import settings from './settings-structure'
|
||||
import usps from './usp-structure'
|
||||
import navigation from './navigation-structure'
|
||||
|
||||
/**
|
||||
* Desk structure overrides
|
||||
@@ -46,7 +47,8 @@ const hiddenDocTypes = (listItem: ListItemBuilder) => {
|
||||
'usp',
|
||||
'navigation',
|
||||
'footerMenu',
|
||||
'utilityMenu'
|
||||
'utilityMenu',
|
||||
'search'
|
||||
].includes(id)
|
||||
}
|
||||
|
||||
@@ -64,9 +66,9 @@ export const structure: StructureResolver = (S, context) =>
|
||||
usps(S, context),
|
||||
sections(S, context),
|
||||
S.divider(),
|
||||
navigation(S, context),
|
||||
S.divider(),
|
||||
settings(S, context),
|
||||
search(S, context),
|
||||
navigation(S, context),
|
||||
S.divider(),
|
||||
...S.documentTypeListItems().filter(hiddenDocTypes),
|
||||
S.divider(),
|
||||
|
34
lib/sanity/desk/search-structure.ts
Normal file
34
lib/sanity/desk/search-structure.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { EyeOpenIcon, MasterDetailIcon } from '@sanity/icons'
|
||||
import { SanityDocument } from 'sanity'
|
||||
import Iframe from 'sanity-plugin-iframe-pane'
|
||||
import { ListItemBuilder } from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
import getPreviewUrl from '../utils/get-preview-url'
|
||||
|
||||
export default defineStructure<ListItemBuilder>((S) =>
|
||||
S.listItem()
|
||||
.title('Search pages')
|
||||
.schemaType('search')
|
||||
.child (
|
||||
S.documentList()
|
||||
.title('Search pages')
|
||||
.filter('_type == "search"')
|
||||
.child(id =>
|
||||
S.document()
|
||||
.schemaType("search")
|
||||
.id(id)
|
||||
.views([
|
||||
S.view
|
||||
.form()
|
||||
.icon(MasterDetailIcon),
|
||||
S.view
|
||||
.component(Iframe)
|
||||
.icon(EyeOpenIcon)
|
||||
.options({
|
||||
url: (doc: SanityDocument) => getPreviewUrl(doc),
|
||||
})
|
||||
.title('Preview')
|
||||
])
|
||||
)
|
||||
)
|
||||
)
|
@@ -178,6 +178,19 @@ export const homePageQuery = `*[_type == "home" && language == $locale][0] {
|
||||
}
|
||||
}`;
|
||||
|
||||
export const searchPageQuery = `*[_type == "search" && language == $locale][0] {
|
||||
_type,
|
||||
title,
|
||||
"locale": language,
|
||||
"translations": *[_type == "translation.metadata" && references(^._id)].translations[].value->{
|
||||
title,
|
||||
"locale": language
|
||||
},
|
||||
seo {
|
||||
${seoFields}
|
||||
}
|
||||
}`;
|
||||
|
||||
// Page query
|
||||
export const pageQuery = `*[_type == "page" && slug.current == $slug && language == $locale][0] {
|
||||
_type,
|
||||
|
@@ -1,19 +1,19 @@
|
||||
import {TagIcon} from '@sanity/icons'
|
||||
import {defineField, defineType} from 'sanity'
|
||||
import {slugWithLocalizedType} from './slugWithLocalizedType'
|
||||
import {languages} from '../../languages'
|
||||
import {validateImage} from '../../utils/validation'
|
||||
import { TagIcon } from '@sanity/icons';
|
||||
import { defineField, defineType } from 'sanity';
|
||||
import { languages } from '../../languages';
|
||||
import { validateImage } from '../../utils/validation';
|
||||
import { slugWithLocalizedType } from '../slugWithLocalizedType';
|
||||
|
||||
const GROUPS = [
|
||||
{
|
||||
name: 'editorial',
|
||||
title: 'Editorial',
|
||||
title: 'Editorial'
|
||||
},
|
||||
{
|
||||
name: 'seo',
|
||||
title: 'SEO',
|
||||
},
|
||||
]
|
||||
title: 'SEO'
|
||||
}
|
||||
];
|
||||
|
||||
export default defineType({
|
||||
name: 'category',
|
||||
@@ -27,7 +27,7 @@ export default defineType({
|
||||
name: 'language',
|
||||
type: 'string',
|
||||
readOnly: true,
|
||||
description: 'Language of this document.',
|
||||
description: 'Language of this document.'
|
||||
// hidden: true,
|
||||
}),
|
||||
// Title
|
||||
@@ -35,7 +35,7 @@ export default defineType({
|
||||
name: 'title',
|
||||
title: 'Title',
|
||||
type: 'string',
|
||||
description: 'Category title.',
|
||||
description: 'Category title.'
|
||||
}),
|
||||
// Slug
|
||||
slugWithLocalizedType('category', 'title'),
|
||||
@@ -60,67 +60,67 @@ export default defineType({
|
||||
name: 'image',
|
||||
type: 'mainImage',
|
||||
title: 'Image',
|
||||
validation: (Rule) => validateImage(Rule, true),
|
||||
validation: (Rule) => validateImage(Rule, true)
|
||||
}),
|
||||
defineField({
|
||||
name: 'description',
|
||||
title: 'Description',
|
||||
type: 'text',
|
||||
rows: 5,
|
||||
description: 'Description of this category.',
|
||||
description: 'Description of this category.'
|
||||
}),
|
||||
defineField({
|
||||
name: 'id',
|
||||
title: 'ID',
|
||||
type: 'number',
|
||||
description: 'Unique ID.',
|
||||
description: 'Unique ID.'
|
||||
}),
|
||||
defineField({
|
||||
name: 'categoryId',
|
||||
title: 'Category ID',
|
||||
type: 'number',
|
||||
description: 'Unique category ID.',
|
||||
description: 'Unique category ID.'
|
||||
}),
|
||||
defineField({
|
||||
name: 'parentId',
|
||||
title: 'Parent ID',
|
||||
type: 'number',
|
||||
description: 'Unique parent category ID.',
|
||||
description: 'Unique parent category ID.'
|
||||
}),
|
||||
// SEO
|
||||
defineField({
|
||||
name: 'seo',
|
||||
title: 'SEO',
|
||||
type: 'seo',
|
||||
group: 'seo',
|
||||
}),
|
||||
group: 'seo'
|
||||
})
|
||||
],
|
||||
orderings: [
|
||||
{
|
||||
name: 'titleAsc',
|
||||
title: 'Title (A-Z)',
|
||||
by: [{field: 'title', direction: 'asc'}],
|
||||
by: [{ field: 'title', direction: 'asc' }]
|
||||
},
|
||||
{
|
||||
name: 'titleDesc',
|
||||
title: 'Title (Z-A)',
|
||||
by: [{field: 'title', direction: 'desc'}],
|
||||
},
|
||||
by: [{ field: 'title', direction: 'desc' }]
|
||||
}
|
||||
],
|
||||
preview: {
|
||||
select: {
|
||||
title: 'title',
|
||||
language: 'language',
|
||||
language: 'language'
|
||||
},
|
||||
prepare(selection) {
|
||||
const {title, language} = selection
|
||||
const currentLang = languages.find((lang) => lang.id === language)
|
||||
const { title, language } = selection;
|
||||
const currentLang = languages.find((lang) => lang.id === language);
|
||||
|
||||
return {
|
||||
title,
|
||||
subtitle: `${currentLang ? currentLang.title : ''}`,
|
||||
media: TagIcon,
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
media: TagIcon
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import {DocumentIcon} from '@sanity/icons'
|
||||
import {defineField} from 'sanity'
|
||||
import {languages} from '../../languages'
|
||||
import {COMPONENT_REFERENCES} from '../../constants'
|
||||
import {slugWithLocalizedType} from './slugWithLocalizedType'
|
||||
import { DocumentIcon } from '@sanity/icons';
|
||||
import { defineField } from 'sanity';
|
||||
import { COMPONENT_REFERENCES } from '../../constants';
|
||||
import { languages } from '../../languages';
|
||||
import { slugWithLocalizedType } from '../slugWithLocalizedType';
|
||||
|
||||
export default defineField({
|
||||
name: 'page',
|
||||
@@ -12,19 +12,19 @@ export default defineField({
|
||||
groups: [
|
||||
{
|
||||
name: 'editorial',
|
||||
title: 'Editorial',
|
||||
title: 'Editorial'
|
||||
},
|
||||
{
|
||||
name: 'seo',
|
||||
title: 'SEO',
|
||||
},
|
||||
title: 'SEO'
|
||||
}
|
||||
],
|
||||
fields: [
|
||||
defineField({
|
||||
name: 'language',
|
||||
type: 'string',
|
||||
readOnly: true,
|
||||
description: 'Language of this document.',
|
||||
description: 'Language of this document.'
|
||||
// hidden: true,
|
||||
}),
|
||||
// Title
|
||||
@@ -33,7 +33,7 @@ export default defineField({
|
||||
title: 'Title',
|
||||
type: 'string',
|
||||
description: 'Page title.',
|
||||
validation: (Rule) => Rule.required(),
|
||||
validation: (Rule) => Rule.required()
|
||||
}),
|
||||
// Slug
|
||||
slugWithLocalizedType('page', 'title'),
|
||||
@@ -44,32 +44,32 @@ export default defineField({
|
||||
type: 'array',
|
||||
group: 'editorial',
|
||||
description: 'Add, reorder, edit or delete page sections.',
|
||||
of: COMPONENT_REFERENCES,
|
||||
of: COMPONENT_REFERENCES
|
||||
}),
|
||||
// SEO
|
||||
defineField({
|
||||
name: 'seo',
|
||||
title: 'SEO',
|
||||
type: 'seo',
|
||||
group: 'seo',
|
||||
}),
|
||||
group: 'seo'
|
||||
})
|
||||
],
|
||||
preview: {
|
||||
select: {
|
||||
seoImage: 'seo.image',
|
||||
title: 'title',
|
||||
language: 'language',
|
||||
language: 'language'
|
||||
},
|
||||
prepare(selection) {
|
||||
const {seoImage, title, language} = selection
|
||||
const { seoImage, title, language } = selection;
|
||||
|
||||
const currentLang = languages.find((lang) => lang.id === language)
|
||||
const currentLang = languages.find((lang) => lang.id === language);
|
||||
|
||||
return {
|
||||
media: seoImage,
|
||||
title,
|
||||
subtitle: `${currentLang ? currentLang.title : ''}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
subtitle: `${currentLang ? currentLang.title : ''}`
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { PackageIcon } from '@sanity/icons';
|
||||
import { defineField, defineType } from 'sanity';
|
||||
import { slugWithLocalizedType } from './slugWithLocalizedType';
|
||||
import { languages } from '../../languages';
|
||||
import { validateImage } from '../../utils/validation';
|
||||
import { slugWithLocalizedType } from '../slugWithLocalizedType';
|
||||
|
||||
const GROUPS = [
|
||||
{
|
||||
|
@@ -12,14 +12,14 @@
|
||||
// ]
|
||||
|
||||
// Document types
|
||||
import blurb from './documents/blurb'
|
||||
import category from './documents/category'
|
||||
import footerMenu from './documents/footerMenu'
|
||||
import page from './documents/page'
|
||||
import product from './documents/product'
|
||||
import productVariant from './documents/productVariant'
|
||||
import blurb from './documents/blurb'
|
||||
import section from './documents/section'
|
||||
import usp from './documents/usp'
|
||||
import footerMenu from './documents/footerMenu'
|
||||
|
||||
const documents = [
|
||||
category,
|
||||
@@ -34,11 +34,11 @@ const documents = [
|
||||
|
||||
// Singleton document types
|
||||
import home from './singletons/home'
|
||||
import search from './singletons/search'
|
||||
import settings from './singletons/settings'
|
||||
import utilityMenu from './singletons/utilityMenu'
|
||||
// import navigation from './singletons/navigation'
|
||||
|
||||
const singletons = [home, settings, utilityMenu]
|
||||
const singletons = [home, settings, utilityMenu, search]
|
||||
|
||||
// Block content
|
||||
import body from './blocks/body'
|
||||
@@ -47,17 +47,17 @@ const blocks = [body]
|
||||
|
||||
// Object types
|
||||
import banner from './objects/banner'
|
||||
import linkExternal from './objects/linkExternal'
|
||||
import linkInternal from './objects/linkInternal'
|
||||
import hero from './objects/hero'
|
||||
import seo from './objects/seo'
|
||||
import mainImage from './objects/mainImage'
|
||||
import slider from './objects/slider'
|
||||
import blurbSection from './objects/blurbSection'
|
||||
import filteredProductList from './objects/filteredProductList'
|
||||
import uspSection from './objects/uspSection'
|
||||
import reusableSection from './objects/reusableSection'
|
||||
import hero from './objects/hero'
|
||||
import linkExternal from './objects/linkExternal'
|
||||
import linkInternal from './objects/linkInternal'
|
||||
import mainImage from './objects/mainImage'
|
||||
import menu from './objects/menu'
|
||||
import reusableSection from './objects/reusableSection'
|
||||
import seo from './objects/seo'
|
||||
import slider from './objects/slider'
|
||||
import uspSection from './objects/uspSection'
|
||||
|
||||
const objects = [
|
||||
linkExternal,
|
||||
|
52
lib/sanity/schemas/singletons/search.tsx
Normal file
52
lib/sanity/schemas/singletons/search.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import { SearchIcon } from '@sanity/icons';
|
||||
import { defineField } from 'sanity';
|
||||
import { languages } from '../../languages';
|
||||
import { slugWithLocalizedType } from '../slugWithLocalizedType';
|
||||
|
||||
export default defineField({
|
||||
name: 'search',
|
||||
title: 'Search',
|
||||
type: 'document',
|
||||
icon: SearchIcon,
|
||||
fields: [
|
||||
defineField({
|
||||
name: 'language',
|
||||
type: 'string',
|
||||
readOnly: true,
|
||||
description: 'Language of this document.'
|
||||
// hidden: true,
|
||||
}),
|
||||
// Title
|
||||
{
|
||||
name: 'title',
|
||||
title: 'Title',
|
||||
type: 'string',
|
||||
description: 'Page title.',
|
||||
validation: (Rule) => Rule.required()
|
||||
},
|
||||
// Slug
|
||||
slugWithLocalizedType('search', 'title'),
|
||||
// SEO
|
||||
defineField({
|
||||
name: 'seo',
|
||||
title: 'SEO',
|
||||
type: 'seo'
|
||||
})
|
||||
],
|
||||
preview: {
|
||||
select: {
|
||||
title: 'title',
|
||||
language: 'language'
|
||||
},
|
||||
prepare(selection) {
|
||||
const { title, language } = selection;
|
||||
|
||||
const currentLang = languages.find((lang) => lang.id === language);
|
||||
|
||||
return {
|
||||
title: `${title}`,
|
||||
subtitle: `${currentLang ? currentLang.title : ''}`
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
@@ -1,7 +1,7 @@
|
||||
import {Rule, Slug} from 'sanity'
|
||||
import { Rule, Slug } from 'sanity';
|
||||
import slugify from "slugify";
|
||||
import { i18n } from "../../languages";
|
||||
import { localizedTypes } from "../../localizedTypes";
|
||||
import { i18n } from "../languages";
|
||||
import { localizedTypes } from "../localizedTypes";
|
||||
|
||||
const MAX_LENGTH = 96
|
||||
|
Reference in New Issue
Block a user