Skip to content

Commit

Permalink
adding README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes committed Jul 29, 2021
1 parent 4918c6f commit 3763e15
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 229 deletions.
45 changes: 45 additions & 0 deletions packages/gatsby-plugin-cms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,48 @@ which would return the follwing json:
}
}
```

## Native Types
CMS plugin has pre-built blocks that speeds up your content types creation. Think of this like a component library that you can import and stitch together to create the content type you desire.
These types include Carousel, Seo, and much more. To use it on your project, justs:
```js
import { Carousel } from '@vtex/gatsby-plugin-cms/native-types'

...

export default {
...
blocks: {
myBlock: {
Carousel,
...
}
}
...
}
```

Check all available blocks, and their definition, at `@vtex/gatsby-plugin-cms/native-types`

### VTEX modules and Native Types
Some VTEX modules have first-class support in our CMS. To enable this support, you need to create your contentTypes with our native types for that specific module.
Below you can find the doc and how these integrations work for each module.

#### Catalog
Sourcing Brands/Categories can be achieved by using `@vtex/gatsby-source-vtex` plugin. This plugin sources a `StoreColletion` node into the Gatsby's data layer containing basic info about a category and brand. Although being handy for creating pages using the [File System Route API](https://www.gatsbyjs.com/docs/reference/routing/file-system-route-api/), `StoreCollection` does not have enought data to create a rich PLP, with banners and much more. For this, you need to extend `StoreCollection` with more data.
To help you extend `StoreCollection` for your business users, we created a native type called `PLP`.

Whenever the CMS finds a node with the `PLP` signature, it will create a customization on the corresponding `StoreCollection` node adding this `PLP` as a foring key on the `StoreCollection` node. This way, you can easily fetch all sections of the `PLP` when rendering the `StoreCollection` page, thus allowing you to add any information you want to the `PLP`.

To use it, just add this to your cms config:
```js
import { PLP } from '@vtex/gatsby-plugin-cms/native-types'

export default {
...
contentTypes: {
...PLP()
},
...
}
```
10 changes: 5 additions & 5 deletions packages/gatsby-plugin-cms/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { fetchAllNodes as fetchAllLocalNodes } from './node-api/cms/sourceLocalN
import {
getCollectionsFromPageContent,
splitCollections,
} from './node-api/catalog/collections'
} from './node-api/catalog'
import type { WithPLP } from './node-api/catalog/index'
import type { BuilderConfig } from './index'
import type {
IBrandCollection,
ICategoryCollection,
IClusterCollection,
} from './native-types'
import type { BuilderConfig } from './index'
import type { WithPLP } from './node-api/catalog/collections'
IBrandCollection,
} from './native-types/blocks/collection'

interface CMSContentType {
id: string
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-cms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Schema extends JSONSchema6 {

export type Schemas = Record<string, Schema>

interface ContentType {
export interface ContentType {
name: string
extraBlocks: Record<string, Schemas>
beforeBlocks: Schemas
Expand Down
12 changes: 0 additions & 12 deletions packages/gatsby-plugin-cms/src/native-types.ts

This file was deleted.

86 changes: 86 additions & 0 deletions packages/gatsby-plugin-cms/src/native-types/blocks/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Seo } from './seo'
import { Sort } from './sort'
import type { ISeo } from './seo'
import type { ISort } from './sort'
import type { Schema } from '../../index'

export interface ICategoryCollection {
sort: keyof ISort
categoryId: string
}

export interface IBrandCollection {
sort: keyof ISort
brandId: string
}

export interface IClusterCollection {
seo: ISeo
sort: keyof ISort
clusterId: string
}

export const isCategoryCollection = (
x: ICollection
): x is ICategoryCollection => typeof (x as any).categoryId === 'string'

export const isBrandCollection = (x: ICollection): x is IBrandCollection =>
typeof (x as any).brandId === 'string'

export const isClusterCollection = (x: ICollection): x is IClusterCollection =>
typeof (x as any).clusterId === 'string'

/**
* Definition of a Collection in the CMS
*/
export type ICollection =
| ICategoryCollection
| IBrandCollection
| IClusterCollection

export const Collection = {
title: 'Collection',
description: 'Definition of a Collection for the CMS',
oneOf: [
{
title: 'Category',
description: 'Configure a Category',
type: 'object',
required: ['categoryId', 'sort'],
properties: {
categoryId: {
title: 'Category ID',
type: 'string',
},
sort: Sort,
},
},
{
title: 'Brand',
description: 'Configure a Brand',
type: 'object',
required: ['brandId', 'sort'],
properties: {
brandId: {
title: 'Brand ID',
type: 'string',
},
sort: Sort,
},
},
{
title: 'Collection',
description: 'Configure a Collection',
type: 'object',
required: ['clusterId', 'sort', 'seo'],
properties: {
clusterId: {
title: 'Collection ID',
type: 'string',
},
sort: Sort,
seo: Seo,
},
},
],
} as Schema
38 changes: 38 additions & 0 deletions packages/gatsby-plugin-cms/src/native-types/blocks/seo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Schema } from '../..'

export interface ISeo {
title: string
slug: string
description: string
}

export const Seo = {
type: 'object',
title: 'Seo',
widget: {
'ui:ObjectFieldTemplate': 'GoogleSeoPreview',
},
required: ['title', 'description', 'slug'],
properties: {
title: {
type: 'string',
title: 'Title',
description:
'Appears in the browser tab and is suggested for search engines',
default: 'Page title',
},
slug: {
type: 'string',
title: 'URL slug',
description: "Final part of the page's address. No spaces allowed.",
default: '/path/to/page',
pattern: '^/([a-zA-Z0-9]|-|/|_)*',
},
description: {
type: 'string',
title: 'Description (Meta description)',
description: 'Suggested for search engines',
default: 'Page description',
},
},
} as Schema
38 changes: 38 additions & 0 deletions packages/gatsby-plugin-cms/src/native-types/blocks/sort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Schema } from '../../index'

export interface ISort {
'""': 'Relevance'
'discount:desc': 'Discount'
'release:desc': 'Release date'
'name:asc': 'Name, ascending'
'name:desc': 'Name, descending'
'orders:desc': 'Sales'
'price:asc': 'Price: Low to High'
'price:desc': 'Price: High to Low'
}

export const Sort = {
title: 'Default ordering',
type: 'string',
default: '""',
enum: [
'""',
'discount:desc',
'release:desc',
'name:asc',
'name:desc',
'orders:desc',
'price:asc',
'price:desc',
],
enumNames: [
'Relevance',
'Discount',
'Release date',
'Name, ascending',
'Name, descending',
'Sales',
'Price: Low to High',
'Price: High to Low',
],
} as Schema
21 changes: 21 additions & 0 deletions packages/gatsby-plugin-cms/src/native-types/contentTypes/plp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Collection } from '../blocks/collection'
import type { ContentType } from '../../index'

export const PLP = ({
extraBlocks = {},
beforeBlocks = {},
afterBlocks = {},
}: Partial<Omit<ContentType, 'name'>>) => ({
plp: {
name: 'PLP',
extraBlocks: {
...extraBlocks,
Parameters: {
...extraBlocks.Parameters,
Collection,
},
},
beforeBlocks,
afterBlocks,
},
})
7 changes: 7 additions & 0 deletions packages/gatsby-plugin-cms/src/native-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { PLP } from './contentTypes/plp'

export { Seo } from './blocks/seo'
export type { ISeo } from './blocks/seo'

export { Sort } from './blocks/sort'
export type { ISort } from './blocks/sort'
67 changes: 0 additions & 67 deletions packages/gatsby-plugin-cms/src/node-api/catalog/collections.ts

This file was deleted.

Loading

0 comments on commit 3763e15

Please sign in to comment.