@stackbit/schema

    0.1.5 • Public • Published

    Stackbit Schema

    Stackbit schema tools

    Install

    npm install @stackbit/schema

    Utility Functions

    loadModels(models)

    Takes raw models map as defined by stackbit.yaml format and returns an array of sanitized models.

    # part of stackbit.yaml
    
    models:
      post:
        type: page
        layout: post
        folder: blog
        fields:
          - type: string
            name: title
            label: Title
            required: true
          # ...fields
      person:
        type: data
        label: Person
        folder: authors
        fields:
          # ...fields
    const stackbitYaml = await parseFile('path/to/stackbit.yaml');
    const models = loadModels(stackbitYaml.models);

    The returned models is a sanitized array of models:

    [
      {
        "name": "post",
        "type": "page",
        "label": "Post",
        "fieldLabel": "title",
        "layout": "post",
        "folder": "blog",
        "fields": [ /* fields */ ]
      },
      {
        "name": "person",
        "type": "data",
        "label": "Person",
        "folder": "authors",
        "fields": [ /* fields */ ]
      }
    ]

    getModelByQuery(query, models)

    Takes a query object representing a loaded content file and models array returned by loadModels() and returns a model matching the query.

    const model = getModelByQuery({ filePath: 'authors/john-doe.json' }, models);
    // model => model for "person" type

    Install

    npm i @stackbit/schema

    DownloadsWeekly Downloads

    905

    Version

    0.1.5

    License

    MIT

    Unpacked Size

    26.8 kB

    Total Files

    9

    Last publish

    Collaborators

    • gromaco
    • eladroz
    • smnh
    • andrejgajdos
    • weissrami
    • tomasb
    • ohadpr
    • rodikh
    • berdav
    • stackbit-admin
    • ausrob
    • vitaliyr
    • denar90
    • youvalv
    • romanlyga
    • ramonsnir
    • ievgenii