hotfix for change to page

develop
HerrHase 2 years ago
parent aa7e2c1ea3
commit bfc5b356ee

@ -25,6 +25,6 @@
<link href="{{ http }}://{{ site.domain }}{{ page.path }}" rel="canonical">
<link rel="alternate" href="{{ http }}://{{ site.domain }}{{ page.path }}" hreflang="{{ site.language }}">
{% endif %}
{% endif %}
{% endmacro %}

@ -31,10 +31,7 @@ class Engine {
// merge data
this._options = assign({}, {
autoescapes: true,
throwOnUndefined: true,
web: {
async: true
}
throwOnUndefined: true
}, options)
this.nunjucks = nunjucks.configure(views, this._options)
@ -63,12 +60,18 @@ class Engine {
* @return {string}
*
*/
render(view, data, done) {
render(page, done) {
// merge data
data = assign(data, this._defaults)
const data = assign({
page: page
}, this._defaults)
this.nunjucks.render(data.page.view, data, (error, response) => {
this.nunjucks.render(view, data, (error, response) => {
if (error) {
console.error(error)
}
const options = configStore.get('options')

@ -0,0 +1,47 @@
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
}
/**
*
*
* @return {object}
*
*/
get() {
return assign({
'content': this._content
}, this._fields)
}
}
module.exports = Block

@ -0,0 +1,111 @@
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
}
/**
* create Page Object
*
*
* @return {object}
*
*/
get() {
return assign({
'content' : this._content,
'blocks' : this._blocks,
'path' : this._pathname + '/' + this._filename,
'filename' : this._filename,
'pathname' : this._pathname
}, this._fields)
}
/**
* 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

@ -60,6 +60,7 @@ class Sitemap {
let result = true
if (page.meta) {
page.meta = Object.entries(page.meta)
page.meta.forEach((meta) => {
if (meta['name'] === 'robots' && meta['content'].includes('noindex')) {
result = false
@ -103,4 +104,4 @@ class Sitemap {
}
}
module.exports =Sitemap
module.exports = Sitemap

@ -3,7 +3,7 @@ const path = require('path')
const orderBy = require('lodash.orderby')
const Page = require('./../models/page.js')
const PageFactory = require('./../factories/page.js')
const Blocks = require('./../queries/blocks.js')
/**
@ -140,8 +140,8 @@ class Pages {
const blocks = this._getBlocks(dirPath + options.parent + '/' + file.name)
// create page object and add to page
const page = new Page(file, options.parent, content, blocks)
this._results.push(page)
const page = new PageFactory(file, options.parent, content, blocks)
this._results.push(page.get())
})
}

@ -73,7 +73,7 @@ class Siteomat {
// run through pages and generate html files
results.forEach((page, index) => {
page.render(this._engine, (error, content) => {
this._engine.render(page, (error, content) => {
// show errors
if (error) {
@ -97,6 +97,7 @@ class Siteomat {
if ((index + 1) === results.length) {
fs.writeFileSync(this._destination + '/sitemap.xml', sitemap.getXmlAsString())
}
})
})
}

Loading…
Cancel
Save