https://github.com/tb/netlify-cms-reader
Read NetlifyCMS config and data
https://github.com/tb/netlify-cms-reader
gatsby gatsby-plugin markdown netlify-cms yaml
Last synced: 6 months ago
JSON representation
Read NetlifyCMS config and data
- Host: GitHub
- URL: https://github.com/tb/netlify-cms-reader
- Owner: tb
- Created: 2019-04-28T22:23:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T03:39:00.000Z (over 3 years ago)
- Last Synced: 2025-02-04T14:49:25.858Z (over 1 year ago)
- Topics: gatsby, gatsby-plugin, markdown, netlify-cms, yaml
- Language: JavaScript
- Size: 813 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Netlify CMS Reader
Read NetlifyCMS config and data.
## Basic usage
```js
const { getConfig, getData } = require('netlify-cms-reader')
const data = await getData(getConfig('static/admin/config.yml'))
```
### Filtered Folder Collections
*Note: For filtered folder collections in `Netlify CMS`, see:
[Filtered folder collections](https://www.netlifycms.org/docs/collection-types/#filtered-folder-collections)*
If a folder collection is filtered, then that collection is returned
by applying the criteria configured in its `filter` property.
As the supported types for the filter value is *not* documented,
this implementation accepts all possible types, so a filter
with the setting `{field: tags, value: ['latest', 'most popular']}`
*is handled,* despite the fact that the UI of `Netlify CMS` (at least
with version `2.10.48`) does *not handle* it despite configuration
for it *is accepted*.
### Collections with Sortable Fields
*Note: For collections with sortable fields in `Netlify CMS`, see
[Sortable fields](https://www.netlifycms.org/docs/configuration-options/#sortable_fields)*
If a folder collection has a `sortableFields` setting, then that
collection is returned by sorting it in increasing order based on
*the first element* in the `sortableFields` array.
E.g. if a collection have a `sortableFields` setting such as `['latest', 'most popular']` then the collection will be returned with the items sorted by the
values of their `latest` field in increasing order.
## Usage with GatsbyJS
```js
const path = require('path')
const { getConfig, getData } = require('netlify-cms-reader')
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions
const { pages } = await getData(getConfig('static/admin/config.yml'))
pages.forEach(page => {
createPage({
path: page.path,
component: path.resolve('src/templates/page.js'),
context: { page },
})
})
}
```