How to use list in Contentlayer

Harry Schiller

April 10th, 2021

81 words

1 min read

A list is an array of values that can be either strings or nested objects.

Options:

  • default (array): A list of default values.
  • of (NestedType): A nested document type definition.

Example:

defineDocumentType(() => ({
  // ...
  fields: {
    tags: {
      type: "list",
      of: { type: "string" }
    }
  }
}));

The default list type expects an array of strings, like this:

---
tags:
  - My First Tag
  - Another Tag
---