Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stackbit/schema
Stackbit schema tools
https://github.com/stackbit/schema
Last synced: about 1 month ago
JSON representation
Stackbit schema tools
- Host: GitHub
- URL: https://github.com/stackbit/schema
- Owner: stackbit
- License: mit
- Created: 2020-07-05T21:31:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T05:19:00.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T01:10:54.485Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 717 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stackbit Schema
Stackbit schema tools
## Install
```bash
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.
```yaml
# part of stackbit.yamlmodels:
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
``````js
const stackbitYaml = await parseFile('path/to/stackbit.yaml');
const models = loadModels(stackbitYaml.models);
```The returned `models` is a sanitized array of models:
```js
[
{
"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.```js
const model = getModelByQuery({ filePath: 'authors/john-doe.json' }, models);
// model => model for "person" type
```