From 1ab50d1089429fee44245d7a3da2aaddf0e178d6 Mon Sep 17 00:00:00 2001 From: HerrHase Date: Sun, 27 Nov 2022 15:25:01 +0100 Subject: [PATCH] adding --- README.md | 27 +++++++++++++++- {resources => example}/site/_images/test.jpeg | Bin {resources => example}/site/about.md | 0 {resources => example}/site/index.md | 0 {resources => example}/site/recipes/index.md | 0 .../site/recipes/noodles/_blocks/hero-1.md | 0 .../site/recipes/noodles/_blocks/hero-2.md | 0 .../site/recipes/noodles/index.md | 0 {resources => example}/site/site.yml | 0 {resources => example}/views/blog.njk | 0 {resources => example}/views/helpers/meta.njk | 0 {resources => example}/views/home.njk | 0 {resources => example}/views/layout.njk | 0 {resources => example}/views/page.njk | 0 {resources => example}/views/post.njk | 0 index.js | 14 ++++----- package-lock.json | 11 +++++++ package.json | 1 + src/happySite.js | 7 +++-- src/queries/pages.js | 29 +++++++++++++++++- test.js | 2 +- 21 files changed, 77 insertions(+), 14 deletions(-) rename {resources => example}/site/_images/test.jpeg (100%) rename {resources => example}/site/about.md (100%) rename {resources => example}/site/index.md (100%) rename {resources => example}/site/recipes/index.md (100%) rename {resources => example}/site/recipes/noodles/_blocks/hero-1.md (100%) rename {resources => example}/site/recipes/noodles/_blocks/hero-2.md (100%) rename {resources => example}/site/recipes/noodles/index.md (100%) rename {resources => example}/site/site.yml (100%) rename {resources => example}/views/blog.njk (100%) rename {resources => example}/views/helpers/meta.njk (100%) rename {resources => example}/views/home.njk (100%) rename {resources => example}/views/layout.njk (100%) rename {resources => example}/views/page.njk (100%) rename {resources => example}/views/post.njk (100%) diff --git a/README.md b/README.md index 70d2cc0..7272184 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,37 @@ to use a Full CMS or Headless CMS like Directus. Rendering the same pages that a seems like a waste of energy. Why not generate from a hierachical file structure. Luckly i i had development a CMS that runs on Markdown File a few years ago as a proof of concept. +## Roadmap + +Next will be, + +* Integrate Eta.js and LiquidJS + ## Installation ``` -not published +npm i --save-dev site-o-mat-webpack-plugin +yarn add --dev site-o-mat-webpack-plugin +``` + +## Configuration + +``` +const SiteOmatWebpackPlugin = require('site-o-mat-webpack-plugin') + +plugins: [ + new SiteOmatWebpackPlugin( + './resources/site', + './resources/views' + ) +] ``` +| Name | Type | Default | Description | +|-------------|-----------|---------|-------------| +| destination | {String} | null | If not set, it will use the public path | +| htmlMinify | {Boolean} | true | Minify Html and remove all Whitespace | + ## Markdown Files ``` diff --git a/resources/site/_images/test.jpeg b/example/site/_images/test.jpeg similarity index 100% rename from resources/site/_images/test.jpeg rename to example/site/_images/test.jpeg diff --git a/resources/site/about.md b/example/site/about.md similarity index 100% rename from resources/site/about.md rename to example/site/about.md diff --git a/resources/site/index.md b/example/site/index.md similarity index 100% rename from resources/site/index.md rename to example/site/index.md diff --git a/resources/site/recipes/index.md b/example/site/recipes/index.md similarity index 100% rename from resources/site/recipes/index.md rename to example/site/recipes/index.md diff --git a/resources/site/recipes/noodles/_blocks/hero-1.md b/example/site/recipes/noodles/_blocks/hero-1.md similarity index 100% rename from resources/site/recipes/noodles/_blocks/hero-1.md rename to example/site/recipes/noodles/_blocks/hero-1.md diff --git a/resources/site/recipes/noodles/_blocks/hero-2.md b/example/site/recipes/noodles/_blocks/hero-2.md similarity index 100% rename from resources/site/recipes/noodles/_blocks/hero-2.md rename to example/site/recipes/noodles/_blocks/hero-2.md diff --git a/resources/site/recipes/noodles/index.md b/example/site/recipes/noodles/index.md similarity index 100% rename from resources/site/recipes/noodles/index.md rename to example/site/recipes/noodles/index.md diff --git a/resources/site/site.yml b/example/site/site.yml similarity index 100% rename from resources/site/site.yml rename to example/site/site.yml diff --git a/resources/views/blog.njk b/example/views/blog.njk similarity index 100% rename from resources/views/blog.njk rename to example/views/blog.njk diff --git a/resources/views/helpers/meta.njk b/example/views/helpers/meta.njk similarity index 100% rename from resources/views/helpers/meta.njk rename to example/views/helpers/meta.njk diff --git a/resources/views/home.njk b/example/views/home.njk similarity index 100% rename from resources/views/home.njk rename to example/views/home.njk diff --git a/resources/views/layout.njk b/example/views/layout.njk similarity index 100% rename from resources/views/layout.njk rename to example/views/layout.njk diff --git a/resources/views/page.njk b/example/views/page.njk similarity index 100% rename from resources/views/page.njk rename to example/views/page.njk diff --git a/resources/views/post.njk b/example/views/post.njk similarity index 100% rename from resources/views/post.njk rename to example/views/post.njk diff --git a/index.js b/index.js index 01ed4c8..7aad09e 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,11 @@ const fs = require('fs') class HappySiteWebpackPlugin { - constructor(source, views, destination = null, options = {}) { - this._options = { - source: source, - views: views, - destination: destination, - options: options - } + constructor(source, views, options = {}) { + + this._source = source + this._views = views + this._options = options if (!fs.existsSync(source)) { throw new Error('source "' + source + '" not found!') @@ -39,7 +37,7 @@ class HappySiteWebpackPlugin { this._options.destination = compilation.outputOptions.path } - const happySite = new HappySite(this._options.source, this._options.views, this._options.destination, this._options.options) + const happySite = new HappySite(this._source, this._views, this._options) happySite.run() }) } diff --git a/package-lock.json b/package-lock.json index 292ac06..142f26d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "html-minifier": "^4.0.0", "js-yaml": "^4.1.0", "lodash.merge": "^4.6.2", + "lodash.orderby": "^4.6.0", "marked": "^4.1.1", "mkdirp": "^1.0.4", "nunjucks": "^3.2.3", @@ -382,6 +383,11 @@ "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" }, + "node_modules/lodash.orderby": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.orderby/-/lodash.orderby-4.6.0.tgz", + "integrity": "sha512-T0rZxKmghOOf5YPnn8EY5iLYeWCpZq8G41FfqoVHH5QDTAFaghJRmAdLiadEDq+ztgM2q5PjA+Z1fOwGrLgmtg==" + }, "node_modules/lower-case": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", @@ -1102,6 +1108,11 @@ "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" }, + "lodash.orderby": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.orderby/-/lodash.orderby-4.6.0.tgz", + "integrity": "sha512-T0rZxKmghOOf5YPnn8EY5iLYeWCpZq8G41FfqoVHH5QDTAFaghJRmAdLiadEDq+ztgM2q5PjA+Z1fOwGrLgmtg==" + }, "lower-case": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", diff --git a/package.json b/package.json index 5101c6b..f33129f 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "html-minifier": "^4.0.0", "js-yaml": "^4.1.0", "lodash.merge": "^4.6.2", + "lodash.orderby": "^4.6.0", "marked": "^4.1.1", "mkdirp": "^1.0.4", "nunjucks": "^3.2.3", diff --git a/src/happySite.js b/src/happySite.js index 5cbc8c1..b768934 100644 --- a/src/happySite.js +++ b/src/happySite.js @@ -29,13 +29,14 @@ class HappySite { * @param {string} destination * */ - constructor(source, views, destination, options = {}) { + constructor(source, views, options = {}) { this._source = source this._views = views - this._destination = destination + this._destination = options.destination + // fill singleton for configuration configStore.set('source', source) - configStore.set('destination', destination) + configStore.set('destination', this._destination) configStore.set('views', views) configStore.set('options', Object.assign({}, { 'minifyHtml': true diff --git a/src/queries/pages.js b/src/queries/pages.js index f928b6e..c442812 100644 --- a/src/queries/pages.js +++ b/src/queries/pages.js @@ -1,6 +1,8 @@ const fs = require('fs') const path = require('path') +const orderBy = require('lodash.orderby') + const Page = require('./../models/page.js') const Blocks = require('./../queries/blocks.js') @@ -51,9 +53,34 @@ class Pages { options = Object.assign({}, this._options, options) this._findFiles(this._dirPath, options) + // + if (options.orderBy && options.orderBy.length > 0) { + this._orderBy(options) + } + return this._results } + /** + * + * + * @param {array} options + * + */ + _orderBy(options) { + options.orderBy.forEach((key, index) => { + + let direction = 'asc' + + if (key.charAt(0) === '-') { + key.slice(0, 1) + direction = 'desc' + } + + this._results = orderBy(this._results, '_fields.' + key, direction) + }) + } + /** * find files * @@ -65,7 +92,7 @@ class Pages { */ _findFiles(dirPath, options) { - // + // getting all files const files = fs.readdirSync(dirPath + options.parent, { withFileTypes: true }) diff --git a/test.js b/test.js index b007457..39881b3 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,4 @@ const HappySite = require('./src/happySite.js') -const happySite = new HappySite('./resources/site', './resources/views', './public') +const happySite = new HappySite('./example/site', './example/views', './public') happySite.run() \ No newline at end of file