hotfix remove models

develop
HerrHase 1 year ago
parent bfc5b356ee
commit f4ccb399b3

@ -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}
*

@ -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 <me@herr-hase.wtf>
* @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

@ -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 <me@herr-hase.wtf>
* @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

@ -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())
})
}

@ -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()
}

Loading…
Cancel
Save