HerrHase 2 years ago
parent 95415fa88f
commit 8dd02ce757

@ -143,7 +143,7 @@ can be used like this,
## Queries ## Queries
Queries can be used in Templates to get Queries can be used in Templates to get Pages.
### Pages ### Pages
@ -160,6 +160,24 @@ or with options,
| parent | {String} | / | Directory for start query | | parent | {String} | / | Directory for start query |
| deep | {Integer} | -1 | Deep of Recursive | | deep | {Integer} | -1 | Deep of Recursive |
| orderBy | {Array} | null | Name of field sorting, a "-" in front of the. Nested fields are also possible. | | orderBy | {Array} | null | Name of field sorting, a "-" in front of the. Nested fields are also possible. |
| limit | {Integer} | null | Limit results |
| filter | {Object} | null | Filtering results by Fields in yaml |
#### Filter
Basic Usage:
```
{
<fieldname>: {
<operator>: <value>
}
}
```
| Name | Description |
|-------------|-------------|
| _eq | Equal Value |
## Sitemap ## Sitemap

@ -0,0 +1,6 @@
---
title: "health goth DIY tattooed"
view: "blog.njk"
meta:
description: "La"
---

@ -0,0 +1,9 @@
---
title: "health goth DIY tattooed"
view: "post.njk"
meta:
description: "DSA yes plz hot chicken green juice"
---
## Normcore cold-pressed ramps DSA
Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund.

@ -0,0 +1,9 @@
---
title: "health goth DIY tattooed"
view: "post.njk"
meta:
description: "DSA yes plz hot chicken green juice"
---
## Normcore cold-pressed ramps DSA
Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund.

@ -1 +1,15 @@
{% extends('layout.njk') %} {% extends('layout.njk') %}
{% block main %}
{% set posts = pageQuery.find({ orderBy: [ '-date_published' ], limit: 1, filter: { view: { _eq: 'post.njk' } } }) %}
{% for post in posts %}
<a class="post" href="{{ post.path }}">
<h2 class="post__title">
{{ post.title }}
</h2>
</a>
{% endfor %}
{% endblock %}

@ -0,0 +1,5 @@
{% extends('layout.njk') %}
{% block main %}
{{ page.content | safe }}
{% endblock %}

@ -1,6 +1,6 @@
{ {
"name": "@helpers/siteomat-webpack-plugin", "name": "@helpers/siteomat-webpack-plugin",
"version": "0.1.0", "version": "0.2.0",
"build": "webpack", "build": "webpack",
"author": "Björn Hase <me@herr-hase.wtf>", "author": "Björn Hase <me@herr-hase.wtf>",
"main": "index.js", "main": "index.js",

@ -48,6 +48,7 @@ class Pages {
*/ */
find(options = {}) { find(options = {}) {
this._results = [] this._results = []
this._count = 0
options = Object.assign({}, this._options, options) options = Object.assign({}, this._options, options)
this._findFiles(this._dirPath, options) this._findFiles(this._dirPath, options)
@ -60,6 +61,28 @@ class Pages {
return this._results return this._results
} }
/**
* filtering single results from query
* if filter is set check result
*
* @param {array} result
* @param {array} options
* @return {boolean}
*
*/
_filter(result, options) {
let isValid = true
for (const [key, value] of Object.entries(options.filter)) {
if (value['_eq'] && result[key] !== value['_eq']) {
isValid = false
}
}
return isValid
}
/** /**
* *
* *
@ -140,6 +163,17 @@ class Pages {
// create page object and add to page // create page object and add to page
const page = new PageFactory(file, options.parent, content, blocks) const page = new PageFactory(file, options.parent, content, blocks)
// check for filters and skip
if (options.filter && !this._filter(page.get(), options)) {
return;
}
// check for filters and skip
if (options.limit && options.limit <= this._results.length) {
return;
}
this._results.push(page.get()) this._results.push(page.get())
}) })
} }

@ -1,7 +1,8 @@
const Siteomat = require('./src/siteomat.js') const Siteomat = require('./src/siteomat.js')
const siteomat = new Siteomat('./example/site', './example/views', { const siteomat = new Siteomat('./example/site', './example/views', {
'destination': './public' 'destination': './public',
'minifyHtml': false
}) })
siteomat.run() siteomat.run()
Loading…
Cancel
Save