Configure properties

⚠ The content source plugin contentlayer-source-notion is currently in Alpha and should not be used in production.


Base configuration

In order to map a configuration to a property you need to provide the id or the name.

  • name|id is used to specify which property to configure (required).
  • description is used to generate comments
  • isRequired if set to true, the content of the pages without this property defined will not be generated (defaults to false)
const Post = defineDatabase(() => ({
  name: 'Post',
  databaseId: '<database_id>',
  properties: [
    {
      name: 'Short description',
      description: 'The post description',
      isRequired: true,
    },
    {
      id: 'x%Fdv',
      description: 'The post status',
      isRequired: true,
    },
  ],
}))

Map properties to specific keys

By mapping properties to specific keys, you can keep the name in your own language in Notion but having it translated in the generated schema.

By using array

const Post = defineDatabase(() => ({
  name: 'Post',
  databaseId: '<database_id>',
  properties: [
    {
      key: 'metaDescription',
      name: 'Short description',
    },
  ],
}))

By using object

const Post = defineDatabase(() => ({
  name: 'Post',
  databaseId: '<database_id>',
  properties: {
    metaDescription: {
      name: 'Short description',
    },
  },
}))

Relation property configuration

Relation properties allows you to define relations between pages.

By setting single to true, the property will be the ID of the relation instead of a list of IDs.

const Category = defineDatabase(() => ({
  name: 'Category',
  databaseId: '<database_id>',
}))

const Post = defineDatabase(() => ({
  name: 'Post',
  databaseId: '<database_id>',
  properties: {
    category: {
      name: 'Category',
      type: 'relation',
      relation: Category,
      single: true,
    },
  },
}))

Rollup properties configuration

A rollup property allows you to aggregate a property of the pages defined in a relation property (e.g. average numbers).

The cool thing is that you only have to configure the relation property and everything will work by itself!


Was this article helpful to you?
Provide feedback

Last edited on March 31, 2023.
Edit this page