diff --git a/example/site/json.yml b/example/site/json.yml new file mode 100644 index 0000000..0e61229 --- /dev/null +++ b/example/site/json.yml @@ -0,0 +1,6 @@ +posts: + orderBy: + - '-date_published' + filter: + view: + _eq: 'post.njk' diff --git a/src/siteomat.js b/src/siteomat.js index 6059a3a..b4aab02 100644 --- a/src/siteomat.js +++ b/src/siteomat.js @@ -56,6 +56,11 @@ class Siteomat { throw new Error('site.yml not found in ' + this._source + '!') } + if (fs.existsSync(this._source + '/json.yml')) { + const file = fs.readFileSync(this._source + '/json.yml', 'utf8') + this._json = parseYamlFile(file) + } + configStore.set('site', this._site) this._engine = new Engine(views, this._site) @@ -100,7 +105,14 @@ class Siteomat { }) }) + + if (this._json) { + for (const [name, options] of Object.entries(this._json)) { + const json = query.find(options) + fs.writeFileSync(this._destination + '/' + name + '.json', JSON.stringify(json)) + } + } } } -module.exports = Siteomat \ No newline at end of file +module.exports = Siteomat