Data files view

Data files/folders are pieces of content that do not belong to any markdown content, but live on their own. Most of the time, these data files are used to store additional information about your project/blog/website that will be used to render the content.

For example:

  • navigation
  • social media links
  • contacts
  • etc.

The data files dashboard allows you to quickly manage your data files.

Data files dashboard

Settings

To use the data files dashboard, you need to configure the extension with the following settings:

  • frontMatter.data.files: Defines how a single data file.
  • frontMatter.data.folders: Defines that all files of a folder need to be treated the same. It can also be used to create new data files.
  • frontMatter.data.types: This only defines the object and its fields. Use this setting, if you want to re-use a data type in various files/folders.

frontMatter.data.files settings

The frontMatter.data.files setting is used to define how a single data file should be treated.

The following properties can be defined:

PropertyDescriptionRequiredDefault
idUnique identifier for the data fileYes
titleTitle of the data fileYes
filePath to the data fileYes
labelFieldField that should be used as the labelNo
fileTypeType of the file (json, yaml, yml)Nojson
singleEntryDefines if the file contains a single entryNofalse
schemaJSON schema definition for the data fileYes
typeID of the data type to use (re-usable schema)No

frontMatter.data.folders settings

The frontMatter.data.folders setting is used to define how a folder with data files should be treated.

The following properties can be defined:

PropertyDescriptionRequiredDefault
idUnique identifier for the data folderYes
pathPath to the data folderYes
labelFieldField that should be used as the labelNo
singleEntryDefines if the files in the folder contain a single entryNofalse
enableFileCreationDefines if new data files can be createdNofalse
fileTypeType of the files (json, yaml, yml)Nojson
schemaJSON schema definition for the data filesYes
typeID of the data type to use (re-usable schema)No

frontMatter.data.types settings

The frontMatter.data.types setting is used to define re-usable data types.

The following properties can be defined:

PropertyDescriptionRequiredDefault
idUnique identifier for the data typeYes
schemaJSON schema definition for the data typeYes

Data fields schema

Each setting requires a schema definition. The schema is defined using the JSON Schema standard.

The following field types are supported:

  • string
  • number
  • boolean
  • array
  • object

When you are using the string type, you can use the multiline property to define if the field is a multiline field.

Registering data files

When you have a data file in which you hold information like for example a list of authors (authors.json), you can register this file in the frontMatter.data.files setting as follows:

Registering a data file
{
  "frontMatter.data.files": [{
    "id": "authors",
    "title": "Authors",
    "file": "[[workspace]]/data/authors.json",
    "labelField": "name",
    "singleEntry": false,
    "schema": {
      "title": "Authors",
      "type": "object",
      "required": [
        "name",
        "url"
      ],
      "properties": {
        "name": {
          "type": "string",
          "title": "Name"
        },
        "url": {
          "type": "string",
          "title": "URL"
        },
        "description": {
          "type": "string",
          "title": "Description"
        }
      }
    }
  }]
}
Important

The singleEntry setting is used to define if the data file is a single entry or a not.

The above sample can be used to manage author data in the authors.json file. Each author record contains a url, name, and description as properties.

Author data example
[
  {
    "name": "Elio Struyf",
    "url": "https://www.eliostruyf.com",
    "description": "Elio is a Microsoft MVP, GitHub Star, and a Google Developer Expert."
  }
]

Data dashboard - Sponsor example

Info

Use the [[workspace]] placeholder to define the workspace folder. The extension will automatically replace this with the workspace folder path.

Registering data folders

When you have a folder with multiple data files of the same type, you can register this folder in the frontMatter.data.folders setting as follows:

Registering a data folder
{
  "frontMatter.data.folders": [{
    "id": "authors",
    "path": "[[workspace]]/data/authors",
    "singleEntry": true,
    "enableFileCreation": true,
    "fileType": "json",
    "schema": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "title": "Name"
        },
        "url": {
          "type": "string",
          "title": "URL"
        },
        "description": {
          "type": "string",
          "title": "Description"
        }
      }
    }
  }]
}
Important

when using data folders, the extension searches for yml, yaml, and json files in the folder.

As the singleEntry setting is set to true. Each data file contains a single entry.

Single entry data example
{
  "name": "Elio Struyf",
  "url": "https://eliostruyf.com",
  "description": "Elio is a Microsoft MVP, GitHub Star, and a Google Developer Expert."
}

Data file creation support

When you have the enableFileCreation property set to true on the folder, you can create new data files directly from the data dashboard. When you open the data dashboard, you will be prompted to create a new data file (if no files are available yet).

Data dashboard - Create new data file

Once the file is created, you can start managing the data.

Data dashboard - Add new data file content

On the main data view, you can see all the data files that are available in the folder.

Data dashboard - Data files view

Re-usable data types

In the above examples, you could see that the data schema is defined in both the file and folder settings. If you want to re-use the schema, you can define the schema in the frontMatter.data.types setting.

You can define the data type as follows:

Defining a data type
{
  "frontMatter.data.types": [{
    "id": "author",
    "schema": {
      "title": "Author",
      "type": "object",
      "required": [
        "name",
        "url"
      ],
      "properties": {
        "name": {
          "type": "string",
          "title": "Name"
        },
        "url": {
          "type": "string",
          "title": "URL"
        },
        "description": {
          "type": "string",
          "title": "Description"
        }
      }
    }
  }]
}

The ID of the data type can be used in the frontMatter.data.files and frontMatter.data.folders settings by defining it as the type property.

Cofiguring the data file

Configuring the data file
{
  "frontMatter.data.files": [{
    "id": "authors",
    "title": "Authors",
    "file": "[[workspace]]/data/authors.json",
    "labelField": "name",
    "singleEntry": false,
    "type": "author"
  }]
}

Configuring the data folder

{
  "frontMatter.data.folders": [{
    "id": "authors",
    "path": "[[workspace]]/data/authors",
    "singleEntry": true,
    "enableFileCreation": true,
    "fileType": "json",
    "type": "author"
  }]
}

Feedback/comments

Last updated on

Did you spot an issue in our documentation, or want to contribute? Edit this page on Github!

Ready to get started?

Special thanks to our backers & sponsors

run.events - Event Management PlatformNetlifyBEJS Community