From 184c5fc61e63066f4a73f050f7897118f3ac4f5d Mon Sep 17 00:00:00 2001 From: HerrHase Date: Mon, 28 Nov 2022 22:58:59 +0100 Subject: [PATCH] adding --- package-lock.json | 37 ++++++++++++++++++++++++-- package.json | 1 + src/config.js | 22 ++++++++++++--- src/{ => engines}/helpers.js | 4 +-- src/{engine.js => engines/nunjucks.js} | 9 ++++--- src/{ => factories}/media.js | 0 src/{ => factories}/sitemap.js | 2 +- src/models/block.js | 13 ++++----- src/models/page.js | 17 ++++++------ src/parsers/markdown.js | 4 +-- src/parsers/yaml.js | 2 +- src/queries/blocks.js | 8 +++--- src/queries/pages.js | 2 +- src/siteomat.js | 12 ++++----- 14 files changed, 94 insertions(+), 39 deletions(-) rename src/{ => engines}/helpers.js (93%) rename src/{engine.js => engines/nunjucks.js} (88%) rename src/{ => factories}/media.js (100%) rename src/{ => factories}/sitemap.js (95%) diff --git a/package-lock.json b/package-lock.json index 3fc9c54..94956f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,14 @@ { - "name": "@/siteomat-webpack-plugin", + "name": "@helpers/siteomat-webpack-plugin", "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "@/siteomat-webpack-plugin", + "name": "@helpers/siteomat-webpack-plugin", "version": "0.1.0", "dependencies": { + "assign-deep": "^1.0.1", "crypto": "^1.0.1", "dayjs": "^1.11.6", "fast-xml-parser": "^4.0.11", @@ -38,6 +39,25 @@ "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" }, + "node_modules/assign-deep": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/assign-deep/-/assign-deep-1.0.1.tgz", + "integrity": "sha512-CSXAX79mibneEYfqLT5FEmkqR5WXF+xDRjgQQuVf6wSCXCYU8/vHttPidNar7wJ5BFmKAo8Wei0rCtzb+M/yeA==", + "dependencies": { + "assign-symbols": "^2.0.2" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/assign-symbols": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-2.0.2.tgz", + "integrity": "sha512-9sBQUQZMKFKcO/C3Bo6Rx4CQany0R0UeVcefNGRRdW2vbmaMOhV1sbmlXcQLcD56juLXbSGTBm0GGuvmrAF8pA==", + "engines": { + "node": ">=6" + } + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -766,6 +786,19 @@ "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" }, + "assign-deep": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/assign-deep/-/assign-deep-1.0.1.tgz", + "integrity": "sha512-CSXAX79mibneEYfqLT5FEmkqR5WXF+xDRjgQQuVf6wSCXCYU8/vHttPidNar7wJ5BFmKAo8Wei0rCtzb+M/yeA==", + "requires": { + "assign-symbols": "^2.0.2" + } + }, + "assign-symbols": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-2.0.2.tgz", + "integrity": "sha512-9sBQUQZMKFKcO/C3Bo6Rx4CQany0R0UeVcefNGRRdW2vbmaMOhV1sbmlXcQLcD56juLXbSGTBm0GGuvmrAF8pA==" + }, "base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", diff --git a/package.json b/package.json index 67a3872..b728f08 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "description": "A Webpack Plugin for generating a Website as Html-Files from a Markdown File Structure", "dependencies": { + "assign-deep": "^1.0.1", "crypto": "^1.0.1", "dayjs": "^1.11.6", "fast-xml-parser": "^4.0.11", diff --git a/src/config.js b/src/config.js index 30f5860..ef28012 100644 --- a/src/config.js +++ b/src/config.js @@ -1,8 +1,13 @@ /** + * ConfigStore * * + * + * @author Björn Hase + * @license http://opensource.org/licenses/MIT The MIT License + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git + * */ - class ConfigStore { constructor() { @@ -15,6 +20,10 @@ class ConfigStore { } /** + * set value by key + * + * @param {String} key + * @param {String|Object} value * */ set(key, value) { @@ -22,10 +31,17 @@ class ConfigStore { } /** + * get value by key * - * + * @param {String} key + * @return {String|Object} */ get(key) { + + if (!this._data?.[key]) { + throw new Error(key + ' not found in ConfigStore!') + } + return this._data[key] } } @@ -33,4 +49,4 @@ class ConfigStore { // create instance const instance = new ConfigStore(); -module.exports =instance \ No newline at end of file +module.exports = instance \ No newline at end of file diff --git a/src/helpers.js b/src/engines/helpers.js similarity index 93% rename from src/helpers.js rename to src/engines/helpers.js index 4a2dbaf..9d171dc 100644 --- a/src/helpers.js +++ b/src/engines/helpers.js @@ -12,8 +12,8 @@ const Media = require('./media.js') * */ -function asset(staticPath) -{ +function asset(staticPath) { + // getting basePath let result = staticPath diff --git a/src/engine.js b/src/engines/nunjucks.js similarity index 88% rename from src/engine.js rename to src/engines/nunjucks.js index 60dfd9c..fae2d25 100644 --- a/src/engine.js +++ b/src/engines/nunjucks.js @@ -2,16 +2,17 @@ const nunjucks = require('nunjucks') const { minify } = require('html-minifier') const fs = require('fs') +const configStore = require('./../config.js') const { asset, resize } = require('./helpers.js') -const PageQuery = require('./queries/pages.js') -const configStore = require('./config.js') +const PageQuery = require('./../queries/pages.js') /** - * engine - handle eta.js + * nunjucks + * * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ class Engine { diff --git a/src/media.js b/src/factories/media.js similarity index 100% rename from src/media.js rename to src/factories/media.js diff --git a/src/sitemap.js b/src/factories/sitemap.js similarity index 95% rename from src/sitemap.js rename to src/factories/sitemap.js index 63e3d84..1869e09 100644 --- a/src/sitemap.js +++ b/src/factories/sitemap.js @@ -6,7 +6,7 @@ const dayjs = require('dayjs') * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ class Sitemap { diff --git a/src/models/block.js b/src/models/block.js index 3b80ece..63b92c6 100644 --- a/src/models/block.js +++ b/src/models/block.js @@ -4,12 +4,12 @@ const parseMarkdownFile = require('./../parsers/markdown.js') /** * Block * - * parsed markdown-file that can contains fields - * as yaml + * parsed markdown-file that can + * contains fields as yaml * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ @@ -26,9 +26,10 @@ class Block { // parse string of file const parsedFile = parseMarkdownFile(fileString) - this._content = parsedFile.content - this._fields = parsedFile.fields + // getting parsed data + this.content = parsedFile.content + this.fields = parsedFile.fields } } -module.exports =Block \ No newline at end of file +module.exports = Block \ No newline at end of file diff --git a/src/models/page.js b/src/models/page.js index dac60be..5c81022 100644 --- a/src/models/page.js +++ b/src/models/page.js @@ -2,6 +2,7 @@ const path = require('path') const slugify = require('slugify') const merge = require('lodash.merge') const nunjucks = require('nunjucks') +const assign = require('assign-deep') const parseMarkdownFile = require('./../parsers/markdown.js') @@ -11,7 +12,7 @@ const parseMarkdownFile = require('./../parsers/markdown.js') * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ @@ -36,15 +37,15 @@ class Page { this.pathname = this._resolvePathname(parent) // fields merge by default values - this._fields = merge({ + this.fields = merge({ view: 'page', meta: { robots: 'index' } }, result.fields) - this._content = result.content - this._blocks = blocks + this.content = result.content + this.blocks = blocks } /** @@ -56,13 +57,13 @@ class Page { */ render(engine, done) { - const page = Object.assign({}, this._fields) + const page = assign({}, this.fields) - page.content = this._content - page.blocks = this._blocks + page.content = this.content + page.blocks = this.blocks page.path = this.pathname + '/' + this.filename - return engine.render(this._fields.view, { + return engine.render(this.fields.view, { page: page }, done) } diff --git a/src/parsers/markdown.js b/src/parsers/markdown.js index 1453ba1..8a3cb93 100644 --- a/src/parsers/markdown.js +++ b/src/parsers/markdown.js @@ -6,7 +6,7 @@ const { marked } = require('marked') * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ @@ -39,4 +39,4 @@ function parseMarkdownFile(fileString) { return result } -module.exports =parseMarkdownFile \ No newline at end of file +module.exports = parseMarkdownFile \ No newline at end of file diff --git a/src/parsers/yaml.js b/src/parsers/yaml.js index 5271da0..7b988e3 100644 --- a/src/parsers/yaml.js +++ b/src/parsers/yaml.js @@ -5,7 +5,7 @@ const yaml = require('js-yaml') * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ diff --git a/src/queries/blocks.js b/src/queries/blocks.js index 855ec52..b21d63a 100644 --- a/src/queries/blocks.js +++ b/src/queries/blocks.js @@ -6,9 +6,10 @@ const Block = require('./../models/block.js') /** * search, filter and find pages * + * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ @@ -22,6 +23,7 @@ class Blocks { */ constructor(dirPath) { + this.FILE_EXTENSION = '.md' this.DIRECTORY_BLOCKS = '_blocks' this._dirPath = dirPath + '/' + this.DIRECTORY_BLOCKS; @@ -45,7 +47,7 @@ class Blocks { /** * find files * - * @param {[type]} dirPath + * @param {string} dirPath * @param {Object} [parent = ''] * */ @@ -59,7 +61,7 @@ class Blocks { files.forEach((file) => { // skip for file that is not markdown - if (file.isFile() && path.extname(file.name) !== '.md') { + if (file.isFile() && path.extname(file.name) !== this.FILE_EXTENSION) { return; } diff --git a/src/queries/pages.js b/src/queries/pages.js index c442812..a09b1cc 100644 --- a/src/queries/pages.js +++ b/src/queries/pages.js @@ -11,7 +11,7 @@ const Blocks = require('./../queries/blocks.js') * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ diff --git a/src/siteomat.js b/src/siteomat.js index c3dc569..3f05e9c 100644 --- a/src/siteomat.js +++ b/src/siteomat.js @@ -2,22 +2,22 @@ const fs = require('fs') const path = require('path') const mkdirp = require('mkdirp') -const Engine = require('./engine.js') -const Sitemap = require('./sitemap.js') +const configStore = require('./config.js') + +const Engine = require('./engines/nunjucks.js') +const Sitemap = require('./factories/sitemap.js') const PagesQuery = require('./queries/pages.js') const parseYamlFile = require('./parsers/yaml.js') -const configStore = require('./config.js') - /** - * Main + * Siteomat * * * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/happy-site-webpack-plugin.git + * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git * */ class Siteomat {