From 443145063fded6d0baa9e008f92940fff58c784e Mon Sep 17 00:00:00 2001 From: HerrHase Date: Wed, 11 Jan 2023 11:04:58 +0100 Subject: [PATCH] adding #7 --- example/site/post2.md | 4 +++- example/views/blog.njk | 4 ++-- example/views/rss.njk | 5 ++-- src/engines/nunjucks.js | 9 +++---- src/queries/pages.js | 52 ++++++++++++++++++++++++----------------- test.js | 4 ++-- 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/example/site/post2.md b/example/site/post2.md index a9052a9..562c2b8 100644 --- a/example/site/post2.md +++ b/example/site/post2.md @@ -5,7 +5,9 @@ date_published: "10.10.2022" excerpt: "ddd" meta: description: "DSA yes plz hot chicken green juice" +tags: + - f --- ## 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. \ No newline at end of file +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. diff --git a/example/views/blog.njk b/example/views/blog.njk index 4332092..3393cdf 100644 --- a/example/views/blog.njk +++ b/example/views/blog.njk @@ -2,7 +2,7 @@ {% block main %} -{% set posts = pageQuery.find({ orderBy: [ '-date_published' ], limit: 2, filter: { view: { _eq: 'post.njk' } } }) %} +{% set posts = pageQuery.find({ orderBy: [ '-date_published' ], limit: 2, filter: { tags: { _in: [ 'tok', 'xxx' ] } } }) %} {% for post in posts %} @@ -12,4 +12,4 @@ {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/example/views/rss.njk b/example/views/rss.njk index 8b41fc1..fd6b357 100644 --- a/example/views/rss.njk +++ b/example/views/rss.njk @@ -3,7 +3,8 @@ {% if (site.https) %} {% set http = 'https' %} {% endif %} - + {% endfor %} - \ No newline at end of file + diff --git a/src/engines/nunjucks.js b/src/engines/nunjucks.js index a1dcbdd..aaccfd8 100644 --- a/src/engines/nunjucks.js +++ b/src/engines/nunjucks.js @@ -57,9 +57,8 @@ class Engine { /** * render * - * @param {string} view - * @param {object} data - * @return {string} + * @param {object} page + * @param {function} done * */ render(page, done) { @@ -77,7 +76,7 @@ class Engine { const options = configStore.get('options') - // if options minifyHtml is set, minify html + // if options minifyHtml is set, minify html, but only if page has type html if (options.minifyHtml === true && data.page.type === 'html') { response = minify(response, { removeComments: true, @@ -85,6 +84,8 @@ class Engine { keepClosingSlash: true, removeOptionalTags: false }) + + // remove empty lines } else { response = response.replace(/^(?:[\t ]*(?:\r?\n|\r))+/gm, '') } diff --git a/src/queries/pages.js b/src/queries/pages.js index 5ec7535..c5cff98 100644 --- a/src/queries/pages.js +++ b/src/queries/pages.js @@ -75,22 +75,44 @@ class Pages { let isValid = true for (const [key, value] of Object.entries(options.filter)) { + + // equal if (value['_eq'] && result[key] !== value['_eq']) { isValid = false } - if (value['_neq'] && result[key] === value['_eq']) { + // not equal + if (value['_neq'] && result[key] === value['_neq']) { isValid = false } - /** + // in + if (value['_in'] && Array.isArray(value['_in'])) { - if (value['_in'] && value['_in'].indexOf(result[key]) !== -1) { - isValid = false - } + // if result no exists + if (!result[key]) { + isValid = false + } - if (value['_nin'] && value['_nin'].indexOf(result[key]) === -1) { - isValid = false + if (Array.isArray(result[key])) { + + let found = false + + result[key].forEach((v, index) => { + if (value['_in'].indexOf(v) !== -1) { + found = true + } + }) + + if (!found) { + isValid = false + } + + } else { + if (value['_in'].indexOf(result[key]) === -1) { + isValid = false + } + } } if (value['_lt'] && result[key] < value['_lt']) { @@ -105,7 +127,7 @@ class Pages { isValid = false } - if (value['_gte'] && result[key] >= value['_gt']) { + if (value['_gte'] && result[key] >= value['_gte']) { isValid = false } @@ -116,18 +138,6 @@ class Pages { if (value['_nnull'] && !result[key]) { isValid = false } - - if (value['_contains'] && !result[key]) { - isValid = false - } - - if (value['_ncontains'] && !result[key]) { - isValid = false - } - - if (value['_regex'] && result[key].test(value['_regex'])) { - isValid = false - }*/ } return isValid @@ -271,4 +281,4 @@ class Pages { } -module.exports = Pages \ No newline at end of file +module.exports = Pages diff --git a/test.js b/test.js index 842abee..721a0c9 100644 --- a/test.js +++ b/test.js @@ -2,7 +2,7 @@ const Siteomat = require('./src/siteomat.js') const siteomat = new Siteomat('./example/site', './example/views', { 'destination': './public', - 'minifyHtml': true + 'minifyHtml': false }) -siteomat.run() \ No newline at end of file +siteomat.run()