develop
HerrHase 1 year ago
parent 4f76b36973
commit 1ab50d1089

@ -9,12 +9,37 @@ to use a Full CMS or Headless CMS like Directus. Rendering the same pages that a
seems like a waste of energy. Why not generate from a hierachical file structure. Luckly i
i had development a CMS that runs on Markdown File a few years ago as a proof of concept.
## Roadmap
Next will be,
* Integrate Eta.js and LiquidJS
## Installation
```
not published
npm i --save-dev site-o-mat-webpack-plugin
yarn add --dev site-o-mat-webpack-plugin
```
## Configuration
```
const SiteOmatWebpackPlugin = require('site-o-mat-webpack-plugin')
plugins: [
new SiteOmatWebpackPlugin(
'./resources/site',
'./resources/views'
)
]
```
| Name | Type | Default | Description |
|-------------|-----------|---------|-------------|
| destination | {String} | null | If not set, it will use the public path |
| htmlMinify | {Boolean} | true | Minify Html and remove all Whitespace |
## Markdown Files
```

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

@ -3,13 +3,11 @@ const fs = require('fs')
class HappySiteWebpackPlugin {
constructor(source, views, destination = null, options = {}) {
this._options = {
source: source,
views: views,
destination: destination,
options: options
}
constructor(source, views, options = {}) {
this._source = source
this._views = views
this._options = options
if (!fs.existsSync(source)) {
throw new Error('source "' + source + '" not found!')
@ -39,7 +37,7 @@ class HappySiteWebpackPlugin {
this._options.destination = compilation.outputOptions.path
}
const happySite = new HappySite(this._options.source, this._options.views, this._options.destination, this._options.options)
const happySite = new HappySite(this._source, this._views, this._options)
happySite.run()
})
}

11
package-lock.json generated

@ -14,6 +14,7 @@
"html-minifier": "^4.0.0",
"js-yaml": "^4.1.0",
"lodash.merge": "^4.6.2",
"lodash.orderby": "^4.6.0",
"marked": "^4.1.1",
"mkdirp": "^1.0.4",
"nunjucks": "^3.2.3",
@ -382,6 +383,11 @@
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
},
"node_modules/lodash.orderby": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.orderby/-/lodash.orderby-4.6.0.tgz",
"integrity": "sha512-T0rZxKmghOOf5YPnn8EY5iLYeWCpZq8G41FfqoVHH5QDTAFaghJRmAdLiadEDq+ztgM2q5PjA+Z1fOwGrLgmtg=="
},
"node_modules/lower-case": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz",
@ -1102,6 +1108,11 @@
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
},
"lodash.orderby": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.orderby/-/lodash.orderby-4.6.0.tgz",
"integrity": "sha512-T0rZxKmghOOf5YPnn8EY5iLYeWCpZq8G41FfqoVHH5QDTAFaghJRmAdLiadEDq+ztgM2q5PjA+Z1fOwGrLgmtg=="
},
"lower-case": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz",

@ -12,6 +12,7 @@
"html-minifier": "^4.0.0",
"js-yaml": "^4.1.0",
"lodash.merge": "^4.6.2",
"lodash.orderby": "^4.6.0",
"marked": "^4.1.1",
"mkdirp": "^1.0.4",
"nunjucks": "^3.2.3",

@ -29,13 +29,14 @@ class HappySite {
* @param {string} destination
*
*/
constructor(source, views, destination, options = {}) {
constructor(source, views, options = {}) {
this._source = source
this._views = views
this._destination = destination
this._destination = options.destination
// fill singleton for configuration
configStore.set('source', source)
configStore.set('destination', destination)
configStore.set('destination', this._destination)
configStore.set('views', views)
configStore.set('options', Object.assign({}, {
'minifyHtml': true

@ -1,6 +1,8 @@
const fs = require('fs')
const path = require('path')
const orderBy = require('lodash.orderby')
const Page = require('./../models/page.js')
const Blocks = require('./../queries/blocks.js')
@ -51,9 +53,34 @@ class Pages {
options = Object.assign({}, this._options, options)
this._findFiles(this._dirPath, options)
//
if (options.orderBy && options.orderBy.length > 0) {
this._orderBy(options)
}
return this._results
}
/**
*
*
* @param {array} options
*
*/
_orderBy(options) {
options.orderBy.forEach((key, index) => {
let direction = 'asc'
if (key.charAt(0) === '-') {
key.slice(0, 1)
direction = 'desc'
}
this._results = orderBy(this._results, '_fields.' + key, direction)
})
}
/**
* find files
*
@ -65,7 +92,7 @@ class Pages {
*/
_findFiles(dirPath, options) {
//
// getting all files
const files = fs.readdirSync(dirPath + options.parent, {
withFileTypes: true
})

@ -1,4 +1,4 @@
const HappySite = require('./src/happySite.js')
const happySite = new HappySite('./resources/site', './resources/views', './public')
const happySite = new HappySite('./example/site', './example/views', './public')
happySite.run()
Loading…
Cancel
Save