diff --git a/example/site/index.md b/example/site/index.md index b974195..5330418 100644 --- a/example/site/index.md +++ b/example/site/index.md @@ -1,6 +1,6 @@ --- title: "health goth DIY tattooed" -view: "home.njk" +view: "page.njk" meta: description: "La" media: diff --git a/example/site/post.md b/example/site/post.md index 82b706f..6aaaafb 100644 --- a/example/site/post.md +++ b/example/site/post.md @@ -1,6 +1,8 @@ --- title: "health goth DIY tattooed" view: "post.njk" +date_published: "09.10.2022" +excerpt: "jjj" meta: description: "DSA yes plz hot chicken green juice" --- diff --git a/example/site/post2.md b/example/site/post2.md index 82b706f..a9052a9 100644 --- a/example/site/post2.md +++ b/example/site/post2.md @@ -1,6 +1,8 @@ --- title: "health goth DIY tattooed" view: "post.njk" +date_published: "10.10.2022" +excerpt: "ddd" meta: description: "DSA yes plz hot chicken green juice" --- diff --git a/example/site/rss.md b/example/site/rss.md new file mode 100644 index 0000000..b46e986 --- /dev/null +++ b/example/site/rss.md @@ -0,0 +1,5 @@ +--- +title: "rss" +view: "rss.njk" +type: "xml" +--- \ No newline at end of file diff --git a/example/views/blog.njk b/example/views/blog.njk index 9db9c0b..4332092 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: 1, filter: { view: { _eq: 'post.njk' } } }) %} +{% set posts = pageQuery.find({ orderBy: [ '-date_published' ], limit: 2, filter: { view: { _eq: 'post.njk' } } }) %} {% for post in posts %} diff --git a/example/views/home.njk b/example/views/home.njk deleted file mode 100644 index a7a5813..0000000 --- a/example/views/home.njk +++ /dev/null @@ -1,5 +0,0 @@ -{% extends('layout.njk') %} - -{% block main %} - -{% endblock %} \ No newline at end of file diff --git a/example/views/rss.njk b/example/views/rss.njk new file mode 100644 index 0000000..b7a02bc --- /dev/null +++ b/example/views/rss.njk @@ -0,0 +1,54 @@ +{% set posts = pageQuery.find({ orderBy: [ '-date_published' ], limit: 10, filter: { view: { _eq: 'post.njk' } } }) %} + +{% set http = 'http' %} + +{% if (site.https) %} + {% set http = 'https' %} +{% endif %} + + + + + {{ site.title }} + + {{ http }}://{{ site.domain }} + + {% if site.description %} + {{ site.description }} + {% endif %} + + {{ dayjs() }} + {{ site.language }}-{{ site.language | upper }} + hourly + 1 + https://gitea.node001.net/HerrHase/siteomat-webpack-plugin + {% for post in posts %} + + {{ post.title }} + {{ http }}://{{ site.domain }}{{ post.path }} + {{ dayjs(post.date_published) }} + + {% if post.excerpt %} + + {{ post.excerpt }} + + {% endif %} + + + + + + {{ http }}://{{ site.domain }}{{ post.path }} + + {% endfor %} + + \ No newline at end of file diff --git a/index.js b/index.js index 23525e4..c0fa109 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,11 @@ const Siteomat = require('./src/siteomat.js') const fs = require('fs') +/** + * + * + * + */ class SiteomatWebpackPlugin { constructor(source, views, options = {}) { diff --git a/package.json b/package.json index bd976b8..f689c97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@helpers/siteomat-webpack-plugin", - "version": "0.2.0", + "version": "0.3.0", "build": "webpack", "author": "Björn Hase ", "main": "index.js", diff --git a/src/engines/nunjucks.js b/src/engines/nunjucks.js index 5a8f346..1c5247e 100644 --- a/src/engines/nunjucks.js +++ b/src/engines/nunjucks.js @@ -6,6 +6,7 @@ const { minify } = require('html-minifier') const configStore = require('./../config.js') const { asset, resize } = require('./helpers.js') const PageQuery = require('./../queries/pages.js') +const dayjs = require('dayjs') /** * nunjucks @@ -48,6 +49,7 @@ class Engine { this._defaults = { site: site, asset: asset, + dayjs: dayjs, pageQuery: new PageQuery(configStore.get('source')) } } diff --git a/src/factories/page.js b/src/factories/page.js index 94271a0..814eaf3 100644 --- a/src/factories/page.js +++ b/src/factories/page.js @@ -32,18 +32,19 @@ class Page { // parse file const result = parseMarkdownFile(fileString) - // adding filename for html as pathname and relative path in structure - this._filename = this._resolveFilename(file) - this._pathname = this._resolvePathname(parent) - // fields merge by default values this._fields = merge({ view: 'page.njk', + type: 'html', meta: { robots: 'index' } }, result.fields) + // adding filename for html as pathname and relative path in structure + this._filename = this._resolveFilename(file) + this._pathname = this._resolvePathname(parent) + this._content = result.content this._blocks = blocks } @@ -62,7 +63,6 @@ class Page { 'path' : this._pathname + '/' + this._filename, 'filename' : this._filename, 'pathname' : this._pathname - }, this._fields) } @@ -87,7 +87,7 @@ class Page { filename = slugify(filename) } - return filename + '.html' + return filename + '.' + this._fields.type } /** diff --git a/src/queries/pages.js b/src/queries/pages.js index dcf4ae4..5ec7535 100644 --- a/src/queries/pages.js +++ b/src/queries/pages.js @@ -78,6 +78,56 @@ class Pages { if (value['_eq'] && result[key] !== value['_eq']) { isValid = false } + + if (value['_neq'] && result[key] === value['_eq']) { + isValid = false + } + + /** + + if (value['_in'] && value['_in'].indexOf(result[key]) !== -1) { + isValid = false + } + + if (value['_nin'] && value['_nin'].indexOf(result[key]) === -1) { + isValid = false + } + + if (value['_lt'] && result[key] < value['_lt']) { + isValid = false + } + + if (value['_lte'] && result[key] <= value['_lte']) { + isValid = false + } + + if (value['_gt'] && result[key] > value['_gt']) { + isValid = false + } + + if (value['_gte'] && result[key] >= value['_gt']) { + isValid = false + } + + if (value['_null'] && result[key]) { + isValid = false + } + + 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 @@ -221,4 +271,4 @@ class Pages { } -module.exports =Pages \ No newline at end of file +module.exports = Pages \ No newline at end of file