add error for missing destination

develop
HerrHase 2 years ago
parent e35e501865
commit aa7e2c1ea3

@ -8,7 +8,7 @@
{{ site.title }} | {{ page.title }} {{ site.title }} | {{ page.title }}
</title> </title>
{{ helpers.meta(page) }} {{ helpers.meta(page, site) }}
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{{ asset('/css/styles.css') }}" rel="stylesheet" type="text/css"> <link href="{{ asset('/css/styles.css') }}" rel="stylesheet" type="text/css">
@ -22,7 +22,7 @@
<div class="bar"> <div class="bar">
<div class="bar__start"> <div class="bar__start">
<h1 class="site-header__title"> <h1 class="site-header__title">
{{ page.title }}
</h1> </h1>
</div> </div>
</div> </div>

@ -1,6 +1,7 @@
const nunjucks = require('nunjucks') const nunjucks = require('nunjucks')
const fs = require('fs') const fs = require('fs')
const assign = require('assign-deep') const assign = require('assign-deep')
const { minify } = require('html-minifier')
const configStore = require('./../config.js') const configStore = require('./../config.js')
const { asset, resize } = require('./helpers.js') const { asset, resize } = require('./helpers.js')
@ -68,6 +69,18 @@ class Engine {
data = assign(data, this._defaults) data = assign(data, this._defaults)
this.nunjucks.render(view, data, (error, response) => { this.nunjucks.render(view, data, (error, response) => {
const options = configStore.get('options')
// if options minifyHtml is set, minify html
if (options.minifyHtml === true) {
response = minify(response, {
removeComments: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true
})
}
done(error, response) done(error, response)
}) })
} }

@ -1,7 +1,7 @@
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const mkdirp = require('mkdirp') const mkdirp = require('mkdirp')
const { minify } = require('html-minifier') const assign = require('assign-deep')
const configStore = require('./config.js') const configStore = require('./config.js')
@ -31,6 +31,11 @@ class Siteomat {
* *
*/ */
constructor(source, views, options = {}) { constructor(source, views, options = {}) {
if (options.destination === undefined) {
throw new Error('Destination is undefined')
}
this._source = source this._source = source
this._views = views this._views = views
this._destination = options.destination this._destination = options.destination
@ -39,7 +44,7 @@ class Siteomat {
configStore.set('source', source) configStore.set('source', source)
configStore.set('destination', this._destination) configStore.set('destination', this._destination)
configStore.set('views', views) configStore.set('views', views)
configStore.set('options', Object.assign({}, { configStore.set('options', assign({
'minifyHtml': true 'minifyHtml': true
}, options)) }, options))
@ -81,17 +86,6 @@ class Siteomat {
return; return;
} }
const options = configStore.get('options')
// if options minifyHtml is set, minify html
if (options.minifyHtml === true) {
content = minify(content, {
removeComments: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true
})
}
// create directories and write file = page // create directories and write file = page
mkdirp(this._destination + page.pathname).then(() => { mkdirp(this._destination + page.pathname).then(() => {
fs.writeFileSync(this._destination + page.pathname + '/' + page.filename, content) fs.writeFileSync(this._destination + page.pathname + '/' + page.filename, content)

@ -1,4 +1,7 @@
const Siteomat = require('./src/siteomat.js') const Siteomat = require('./src/siteomat.js')
const siteomat = new Siteomat('./example/site', './example/views', './public') const siteomat = new Siteomat('./example/site', './example/views', {
'destination': './public'
})
siteomat.run() siteomat.run()
Loading…
Cancel
Save