From f4ccb399b3622e3821886387d42de49909b29b0c Mon Sep 17 00:00:00 2001 From: HerrHase Date: Fri, 2 Dec 2022 15:16:40 +0100 Subject: [PATCH] hotfix remove models --- src/factories/block.js | 4 +- src/models/block.js | 35 ------------- src/models/page.js | 113 ----------------------------------------- src/queries/blocks.js | 9 ++-- src/queries/pages.js | 5 +- 5 files changed, 8 insertions(+), 158 deletions(-) delete mode 100644 src/models/block.js delete mode 100644 src/models/page.js diff --git a/src/factories/block.js b/src/factories/block.js index 4be1ad9..4234165 100644 --- a/src/factories/block.js +++ b/src/factories/block.js @@ -1,6 +1,8 @@ const path = require('path') const parseMarkdownFile = require('./../parsers/markdown.js') +const assign = require('assign-deep') + /** * Block * @@ -32,7 +34,7 @@ class Block { } /** - * + * * * @return {object} * diff --git a/src/models/block.js b/src/models/block.js deleted file mode 100644 index 63b92c6..0000000 --- a/src/models/block.js +++ /dev/null @@ -1,35 +0,0 @@ -const path = require('path') -const parseMarkdownFile = require('./../parsers/markdown.js') - -/** - * Block - * - * 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/siteomat-webpack-plugin.git - * - */ - -class Block { - - /** - * - * - * @param {string} fileString - * - */ - constructor(fileString) { - - // parse string of file - const parsedFile = parseMarkdownFile(fileString) - - // getting parsed data - this.content = parsedFile.content - this.fields = parsedFile.fields - } -} - -module.exports = Block \ No newline at end of file diff --git a/src/models/page.js b/src/models/page.js deleted file mode 100644 index bbf04e1..0000000 --- a/src/models/page.js +++ /dev/null @@ -1,113 +0,0 @@ -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') - -/** - * Page - * - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ - -class Page { - - /** - * - * - * @param {object} file - * @param {string} parent - * @param {string} fileString - * @param {object} [blocks=null] - * - */ - constructor(file, parent, fileString, blocks = {}) { - - // 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', - meta: { - robots: 'index' - } - }, result.fields) - - this.content = result.content - this.blocks = blocks - } - - /** - * render view of page - * - * - * @return {string} - * - */ - render(engine, done) { - - const page = merge({}, this.fields) - - page.content = this.content - page.blocks = this.blocks - page.path = this.pathname + '/' + this.filename - - return engine.render(this.fields.view, { - page: page - }, done) - } - - /** - * create html-filename = filename - * - * @param {string} file - * @return {string} - * - */ - _resolveFilename(file) { - - let filename = file.name - - if (filename === 'index.md') { - filename = 'index' - } else { - if (path.extname(filename) === '.md') { - filename = filename.replace('.md', '') - } - - filename = slugify(filename) - } - - return filename + '.html' - } - - /** - * pathname = parent - * - * @param {string} parent - * @return {string} - * - */ - _resolvePathname(parent) { - let pathname = parent - - if (parent === '/') { - pathname = '' - } - - return pathname - } -} - -module.exports =Page \ No newline at end of file diff --git a/src/queries/blocks.js b/src/queries/blocks.js index b21d63a..baba849 100644 --- a/src/queries/blocks.js +++ b/src/queries/blocks.js @@ -1,7 +1,7 @@ const fs = require('fs') const path = require('path') -const Block = require('./../models/block.js') +const BlockFactory = require('./../factories/block.js') /** * search, filter and find pages @@ -79,17 +79,14 @@ class Blocks { } // create page object and add to page - const block = new Block(fileString) + const block = new BlockFactory(fileString) const blockname = this._parseBlockname(file.name) if (!this._results[blockname]) { this._results[blockname] = [] } - this._results[blockname].push({ - fields: block._fields, - content: block._content - }) + this._results[blockname].push(block.get()) }) } diff --git a/src/queries/pages.js b/src/queries/pages.js index 37c1a22..5af8098 100644 --- a/src/queries/pages.js +++ b/src/queries/pages.js @@ -1,10 +1,9 @@ const fs = require('fs') const path = require('path') - const orderBy = require('lodash.orderby') const PageFactory = require('./../factories/page.js') -const Blocks = require('./../queries/blocks.js') +const BlocksQuery = require('./../queries/blocks.js') /** * Pages - search, filter and find pages @@ -153,7 +152,7 @@ class Pages { * */ _getBlocks(dirPath) { - const blocksQuery = new Blocks(dirPath) + const blocksQuery = new BlocksQuery(dirPath) return blocksQuery.find() }