diff --git a/README.md b/README.md index 5cb429f..3c544d7 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,20 @@ # Site-O-Mat Webpack Plugin -A Webpack Plugin for generating a Website as Html-Files from a Markdown-File Structure. - -Why? The Main reason i had to update some Websites, but realize there were no benefit -to use a Full CMS or Headless CMS like Directus. Rendering the same pages that a rarely updated -seems like a waste of energy. Why not generate from a hierarchical file structure. Luckily i -i had development a CMS, a few years ago, that runs on Markdown Files it had been never -finished, it was a proof of concept. - -## Roadmap - -Next will be, - -* Some Tests -* Filtering for Queries -* Standalone, handle Webpack only as wrapper - -Maybe later, - -* Integrate Eta.js and LiquidJS -* Hooks for handle generic content +A Webpack Plugin that wraps [@site-o-mat/core](https://gitea.node001.net/site-o-mat/core). ## Installation Setup this registry in your project .npmrc file: ``` -@helpers:registry=https://gitea.node001.net/api/packages/HerrHase/npm/ +@helpers:registry=https://gitea.node001.net/api/packages/site-o-mat/npm/ ``` Install with npm or yarn ``` -npm i --save-dev @helpers/siteomat-webpack-plugin -yarn add --dev @helpers/siteomat-webpack-plugin +npm i --save-dev @site-o-mat/webpack-plugin +yarn add --dev @site-o-mat/webpack-plugin ``` ## Configuration @@ -41,7 +22,7 @@ yarn add --dev @helpers/siteomat-webpack-plugin Basic Usage: ``` -const SiteomatWebpackPlugin = require('siteomat-webpack-plugin') +const SiteomatWebpackPlugin = require('@site-o-mat/webpack-plugin') plugins: [ new SiteomatWebpackPlugin( @@ -64,176 +45,3 @@ plugins: [ ) ] ``` - -| 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 | - -## Pages - -Pages are Markdown-Files, they are separates in two parts. First part is a yaml-Section, - -``` ---- -title: "health goth DIY tattooed" -view: "home.njk" -meta: - description: "La" -media: - teaser: - src: "_images/test.jpeg" - alt: "cold-pressed" ---- -``` - -The yaml-Section will be parsed as an Object and available in the Templates. The -second part of the File will be parsed as Markdown, but it could be also empty. - -Default type for Pages is **html**. - -## Nesting - -A Page can be a single Markdown-File, or a Directory with a index-File inside. -The Name of a file or a directory will the name of the html-File. To create Sub-pages, -create Sub-directories. - -This Structure, - -``` -index.md -about-me.md -blog -└ index.md - belly-polaroid-subway.md -``` - -will be, - -``` -index.html -about-me.html -blog.html -blog/belly-polaroid-subway.html -``` - -## Blocks - -Each Page can have Blocks. Blocks are like Pages, but they are only accessible -for a single Page. To add Blocks to a page, add a "_blocks"-Directory -to the Directory of the Page. - -Markdown-Files in a "_blocks"-Directory will be automatic accessible for a Page. The yaml-Section is Optional. - -``` -recipes -└ index.md - _blocks - └ hero-1.md - hero-2.md - hero-3.md -``` - -Blocks will be Grouped by there name, and sorted by the number at the end. The "hero"-Files -can be used like this, - -``` -{% hero in page.blocks.hero %} - {{ hero.content }} -{% endFor %} -``` - -## Queries - -Queries can be used in Templates to get Pages. - -### Pages - -Basic Usage: - -``` -pageQuery.find() -``` - -or with options, - -| Name | Type | Default | Description | -|-------------|-----------|---------|-------------| -| parent | {String} | / | Directory for start query | -| deep | {Integer} | -1 | Deep of Recursive | -| orderBy | {Array} | null | Name of field sorting, a "-" in front of the. Nested fields are also possible. | -| limit | {Integer} | null | Limit results | -| filter | {Object} | null | Filtering results by Fields in yaml | - -#### Filter - -Basic Usage: - -``` -{ - : { - : - } -} -``` - -| Name | Description | -|-------------|-------------| -| _eq | Equal Value | - -## Sitemap - -Sitemap will be generating by Pages. Pages will be only add to Sitemap, if the have meta-robots is set -to "index". Pages default is "index". - -## Templates - -At this Time only [https://mozilla.github.io/nunjucks/](Nunjunks) is used for Templating. - -### Nunjunks - -#### Functions - -##### asset(path) - -This function handle manifest-File from [https://laravel-mix.com/](Laravel-Mix). - -``` - -``` - -#### Filters - -##### resize - -The Filter is using [https://github.com/lovell/sharp](sharp), for crop, resize and -optimize Images. The Filter needs a relative Path in the File Structure. - -Basic Usage: - -``` -{% page.teaser.src | resize({ 'width': '300' }) %} -``` - -Add options: - -``` -{% page.teaser.src | resize({ 'width': '300' }, { sigma: 2 }) %} -``` - -## Json - -Results from PageQuery can also be created as json-File. The can use with a -simple API [https://gitea.node001.net/HerrHase/siteomat-api](https://gitea.node001.net/HerrHase/siteomat-api). Create a -File "json.yml" and add options. - -Basic Usage: - -``` -posts: - orderBy: - - '-date_published' - filter: - view: - _eq: 'post.njk' -``` diff --git a/example/site/_images/test.jpeg b/example/site/_images/test.jpeg deleted file mode 100644 index 028d66e..0000000 Binary files a/example/site/_images/test.jpeg and /dev/null differ diff --git a/example/site/about.md b/example/site/about.md deleted file mode 100644 index 138a9ce..0000000 --- a/example/site/about.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "page.njk" -meta: - description: "DSA yes plz hot chicken green juice" ---- -## Normcore cold-pressed ramps DSA - -Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund. - -## Palo santo leggings normcore aesthetic - -bicycle rights sartorial godard slow-carb thundercats art party cray JOMO. Truffaut four dollar toast hoodie pour-over. Fanny pack iPhone jean shorts tote bag, master cleanse succulents tbh fixie gatekeep pok pok letterpress cornhole. Dreamcatcher tattooed hot chicken gatekeep, glossier salvia 8-bit cred. Fit lomo chillwave cold-pressed humblebrag narwhal. Meggings edison bulb fanny pack irony af pug pok pok whatever vexillologist vibecession cred butcher trust fund chia. - -## Bitters kale chips chambray activated charcoal - -wolf keffiyeh hell of selfies. Wolf readymade shoreditch flexitarian venmo single-origin coffee, knausgaard fit actually street art cold-pressed iPhone gatekeep. Migas bruh adaptogen semiotics marfa pickled yuccie. Locavore normcore lomo, shoreditch fashion axe actually glossier iPhone photo booth blue bottle DIY XOXO williamsburg. Pinterest whatever taxidermy, kale chips prism XOXO schlitz twee tote bag woke swag. Wayfarers fashion axe heirloom humblebrag synth. Whatever succulents PBR&B, pop-up enamel pin echo park tonx stumptown taiyaki. \ No newline at end of file diff --git a/example/site/blog.md b/example/site/blog.md deleted file mode 100644 index cc2c927..0000000 --- a/example/site/blog.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "blog.njk" -meta: - description: "La" ---- \ No newline at end of file diff --git a/example/site/index.md b/example/site/index.md deleted file mode 100644 index 5330418..0000000 --- a/example/site/index.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "page.njk" -meta: - description: "La" -media: - teaser: - src: "_images/test.jpeg" - alt: "cold-pressed" ---- -## Normcore cold-pressed ramps DSA - -Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund. - -## Palo santo leggings normcore aesthetic - -bicycle rights sartorial godard slow-carb thundercats art party cray JOMO. Truffaut four dollar toast hoodie pour-over. Fanny pack iPhone jean shorts tote bag, master cleanse succulents tbh fixie gatekeep pok pok letterpress cornhole. Dreamcatcher tattooed hot chicken gatekeep, glossier salvia 8-bit cred. Fit lomo chillwave cold-pressed humblebrag narwhal. Meggings edison bulb fanny pack irony af pug pok pok whatever vexillologist vibecession cred butcher trust fund chia. - -## Bitters kale chips chambray activated charcoal - -wolf keffiyeh hell of selfies. Wolf readymade shoreditch flexitarian venmo single-origin coffee, knausgaard fit actually street art cold-pressed iPhone gatekeep. Migas bruh adaptogen semiotics marfa pickled yuccie. Locavore normcore lomo, shoreditch fashion axe actually glossier iPhone photo booth blue bottle DIY XOXO williamsburg. Pinterest whatever taxidermy, kale chips prism XOXO schlitz twee tote bag woke swag. Wayfarers fashion axe heirloom humblebrag synth. Whatever succulents PBR&B, pop-up enamel pin echo park tonx stumptown taiyaki. diff --git a/example/site/json.yml b/example/site/json.yml deleted file mode 100644 index 0e61229..0000000 --- a/example/site/json.yml +++ /dev/null @@ -1,6 +0,0 @@ -posts: - orderBy: - - '-date_published' - filter: - view: - _eq: 'post.njk' diff --git a/example/site/post.md b/example/site/post.md deleted file mode 100644 index 6aaaafb..0000000 --- a/example/site/post.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "post.njk" -date_published: "09.10.2022" -excerpt: "jjj" -meta: - description: "DSA yes plz hot chicken green juice" ---- -## Normcore cold-pressed ramps DSA - -Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund. \ No newline at end of file diff --git a/example/site/post2.md b/example/site/post2.md deleted file mode 100644 index ad342e2..0000000 --- a/example/site/post2.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "post.njk" -date_published: "10.10.2022" -excerpt: "ddd" -meta: - description: "DSA yes plz hot chicken green juice" -tags: - - xxx ---- -## Normcore cold-pressed ramps DSA - -Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund. diff --git a/example/site/recipes/index.md b/example/site/recipes/index.md deleted file mode 100644 index 8933fe4..0000000 --- a/example/site/recipes/index.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "page.njk" -meta: - description: "DSA yes plz hot chicken green juice" - robots: "index, nofollow" ---- \ No newline at end of file diff --git a/example/site/recipes/noodles/_blocks/hero-1.md b/example/site/recipes/noodles/_blocks/hero-1.md deleted file mode 100644 index cac8941..0000000 --- a/example/site/recipes/noodles/_blocks/hero-1.md +++ /dev/null @@ -1 +0,0 @@ -lkjlkjlkj \ No newline at end of file diff --git a/example/site/recipes/noodles/_blocks/hero-2.md b/example/site/recipes/noodles/_blocks/hero-2.md deleted file mode 100644 index e34ba9e..0000000 --- a/example/site/recipes/noodles/_blocks/hero-2.md +++ /dev/null @@ -1 +0,0 @@ -kljkljlkj \ No newline at end of file diff --git a/example/site/recipes/noodles/index.md b/example/site/recipes/noodles/index.md deleted file mode 100644 index 8933fe4..0000000 --- a/example/site/recipes/noodles/index.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "page.njk" -meta: - description: "DSA yes plz hot chicken green juice" - robots: "index, nofollow" ---- \ No newline at end of file diff --git a/example/site/rss.md b/example/site/rss.md deleted file mode 100644 index b46e986..0000000 --- a/example/site/rss.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: "rss" -view: "rss.njk" -type: "xml" ---- \ No newline at end of file diff --git a/example/site/site.yml b/example/site/site.yml deleted file mode 100644 index cd3cbb5..0000000 --- a/example/site/site.yml +++ /dev/null @@ -1,5 +0,0 @@ -title: "test" -language: "en" -domain: "test.io" -https: true -description: "why" \ No newline at end of file diff --git a/example/views/blog.njk b/example/views/blog.njk deleted file mode 100644 index 3393cdf..0000000 --- a/example/views/blog.njk +++ /dev/null @@ -1,15 +0,0 @@ -{% extends('layout.njk') %} - -{% block main %} - -{% set posts = pageQuery.find({ orderBy: [ '-date_published' ], limit: 2, filter: { tags: { _in: [ 'tok', 'xxx' ] } } }) %} - -{% for post in posts %} - -

- {{ post.title }} -

-
-{% endfor %} - -{% endblock %} diff --git a/example/views/helpers/meta.njk b/example/views/helpers/meta.njk deleted file mode 100644 index 362b7dc..0000000 --- a/example/views/helpers/meta.njk +++ /dev/null @@ -1,30 +0,0 @@ -{# handle meta in templates #} - -{% macro meta(page, site) %} - {% if (page.meta) %} - - {% set hasCannocial = false %} - - {% for key, content in page.meta %} - - - {# check for index in robots if set page has canonical #} - {% if (key === 'robots' and content.indexOf('index') !== -1 and content.indexOf('noindex') === -1) %} - {% set hasCannocial = true %} - {% endif %} - {% endfor %} - - {# check if page has canonical #} - {% if (hasCannocial) %} - {% set http = 'http' %} - - {% if (site.https) %} - {% set http = site.https %} - {% endif %} - - - - {% endif %} - - {% endif %} -{% endmacro %} \ No newline at end of file diff --git a/example/views/layout.njk b/example/views/layout.njk deleted file mode 100644 index 2222f58..0000000 --- a/example/views/layout.njk +++ /dev/null @@ -1,54 +0,0 @@ -{% import "helpers/meta.njk" as helpers %} - - - - - - - {{ site.title }} | {{ page.title }} - - - {{ helpers.meta(page, site) }} - - - - - {% block addHead %}{% endblock %} - - - - - - -
-
-
-
- {% block main %}{% endblock %} -
-
-
-
- -
-
-
-
- MIT License -
-
-
-
- - - {% block addFooter %}{% endblock %} - - \ No newline at end of file diff --git a/example/views/page.njk b/example/views/page.njk deleted file mode 100644 index e3728e2..0000000 --- a/example/views/page.njk +++ /dev/null @@ -1,5 +0,0 @@ -{% extends('layout.njk') %} - -{% block main %} -{{ page.content | safe }} -{% endblock %} \ No newline at end of file diff --git a/example/views/post.njk b/example/views/post.njk deleted file mode 100644 index e3728e2..0000000 --- a/example/views/post.njk +++ /dev/null @@ -1,5 +0,0 @@ -{% extends('layout.njk') %} - -{% block main %} -{{ page.content | safe }} -{% endblock %} \ No newline at end of file diff --git a/example/views/rss.njk b/example/views/rss.njk deleted file mode 100644 index fd6b357..0000000 --- a/example/views/rss.njk +++ /dev/null @@ -1,51 +0,0 @@ -{% set posts = pageQuery.find({ orderBy: [ '-date_published' ], limit: 10, filter: { view: { _eq: 'post.njk' } } }) %} -{% set http = 'http' %} -{% if (site.https) %} - {% set http = 'https' %} -{% endif %} - - - - {{ site.title }} - - {{ http }}://{{ site.domain }} - - {% if site.description %} - {{ site.description }} - {% endif %} - - {{ dayjs() }} - {{ site.language }}-{{ site.language | upper }} - hourly - 1 - https://gitea.node001.net/HerrHase/siteomat-webpack-plugin - {% for post in posts %} - - {{ post.title }} - {{ http }}://{{ site.domain }}{{ post.path }} - {{ dayjs(post.date_published) }} - - {% if post.excerpt %} - - {{ post.excerpt }} - - {% endif %} - - - - - - {{ http }}://{{ site.domain }}{{ post.path }} - - {% endfor %} - - diff --git a/index.js b/index.js index c0fa109..ecaae62 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const Siteomat = require('./src/siteomat.js') +const Siteomat = require('@site-o-mat/core') const fs = require('fs') /** @@ -48,4 +48,4 @@ class SiteomatWebpackPlugin { } } -module.exports = SiteomatWebpackPlugin \ No newline at end of file +module.exports = SiteomatWebpackPlugin diff --git a/package.json b/package.json index 4867d4d..c69d6c9 100644 --- a/package.json +++ b/package.json @@ -1,36 +1,15 @@ { - "name": "@helpers/siteomat-webpack-plugin", - "version": "0.5.0", + "name": "@site-o-mat/webpack-plugin", + "version": "0.1.0", "build": "webpack", "author": "Björn Hase ", "main": "index.js", "repository": { "type": "git", - "url": "git@gitea.node001.net:HerrHase/siteomat-webpack-plugin.git" - }, - "scripts": { - "test": "mocha" + "url": "git@gitea.node001.net:site-o-mat/webpack-plugin.git" }, "description": "A Webpack Plugin for generating a Website as Html-Files from a Markdown File Structure", "dependencies": { - "@helpers/siteomat-query": "^0.1.0", - "assign-deep": "^1.0.1", - "crypto": "^1.0.1", - "dayjs": "^1.11.6", - "fast-xml-parser": "^4.0.11", - "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", - "sharp": "^0.31.1", - "slugify": "^1.6.5", - "yaml": "^2.1.3" - }, - "devDependencies": { - "chai": "^4.3.7", - "mocha": "^10.2.0" + "@site-o-mat/core": "^0.1.0" } } diff --git a/ressources/_blocks/block-1.md b/ressources/_blocks/block-1.md deleted file mode 100644 index e149f96..0000000 --- a/ressources/_blocks/block-1.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "health goth DIY tattooed" ---- -## Normcore cold-pressed ramps DSA - -Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund. - -## Palo santo leggings normcore aesthetic - -bicycle rights sartorial godard slow-carb thundercats art party cray JOMO. Truffaut four dollar toast hoodie pour-over. Fanny pack iPhone jean shorts tote bag, master cleanse succulents tbh fixie gatekeep pok pok letterpress cornhole. Dreamcatcher tattooed hot chicken gatekeep, glossier salvia 8-bit cred. Fit lomo chillwave cold-pressed humblebrag narwhal. Meggings edison bulb fanny pack irony af pug pok pok whatever vexillologist vibecession cred butcher trust fund chia. - -## Bitters kale chips chambray activated charcoal - -wolf keffiyeh hell of selfies. Wolf readymade shoreditch flexitarian venmo single-origin coffee, knausgaard fit actually street art cold-pressed iPhone gatekeep. Migas bruh adaptogen semiotics marfa pickled yuccie. Locavore normcore lomo, shoreditch fashion axe actually glossier iPhone photo booth blue bottle DIY XOXO williamsburg. Pinterest whatever taxidermy, kale chips prism XOXO schlitz twee tote bag woke swag. Wayfarers fashion axe heirloom humblebrag synth. Whatever succulents PBR&B, pop-up enamel pin echo park tonx stumptown taiyaki. diff --git a/ressources/_blocks/block-2.md b/ressources/_blocks/block-2.md deleted file mode 100644 index e149f96..0000000 --- a/ressources/_blocks/block-2.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "health goth DIY tattooed" ---- -## Normcore cold-pressed ramps DSA - -Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund. - -## Palo santo leggings normcore aesthetic - -bicycle rights sartorial godard slow-carb thundercats art party cray JOMO. Truffaut four dollar toast hoodie pour-over. Fanny pack iPhone jean shorts tote bag, master cleanse succulents tbh fixie gatekeep pok pok letterpress cornhole. Dreamcatcher tattooed hot chicken gatekeep, glossier salvia 8-bit cred. Fit lomo chillwave cold-pressed humblebrag narwhal. Meggings edison bulb fanny pack irony af pug pok pok whatever vexillologist vibecession cred butcher trust fund chia. - -## Bitters kale chips chambray activated charcoal - -wolf keffiyeh hell of selfies. Wolf readymade shoreditch flexitarian venmo single-origin coffee, knausgaard fit actually street art cold-pressed iPhone gatekeep. Migas bruh adaptogen semiotics marfa pickled yuccie. Locavore normcore lomo, shoreditch fashion axe actually glossier iPhone photo booth blue bottle DIY XOXO williamsburg. Pinterest whatever taxidermy, kale chips prism XOXO schlitz twee tote bag woke swag. Wayfarers fashion axe heirloom humblebrag synth. Whatever succulents PBR&B, pop-up enamel pin echo park tonx stumptown taiyaki. diff --git a/ressources/default.md b/ressources/default.md deleted file mode 100644 index 997e599..0000000 --- a/ressources/default.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "health goth DIY tattooed" -view: "page.njk" -meta: - description: "DSA yes plz hot chicken green juice" ---- -## Normcore cold-pressed ramps DSA - -Normcore cold-pressed ramps DSA yes plz hot chicken green juice succulents leggings messenger bag truffaut iceland pabst ethical godard. Semiotics air plant marfa, drinking vinegar authentic iceland pug fit cloud bread cronut kickstarter glossier crucifix tumeric. Chicharrones polaroid flexitarian, seitan lumbersexual viral fam master cleanse four dollar toast scenester. Succulents poutine vegan keffiyeh meh, health goth DIY tattooed. Praxis roof party celiac chartreuse banjo butcher you probably haven't heard of them schlitz beard. Ethical tattooed kinfolk, cliche vegan messenger bag mukbang dreamcatcher cloud bread farm-to-table gatekeep trust fund. - -## Palo santo leggings normcore aesthetic - -bicycle rights sartorial godard slow-carb thundercats art party cray JOMO. Truffaut four dollar toast hoodie pour-over. Fanny pack iPhone jean shorts tote bag, master cleanse succulents tbh fixie gatekeep pok pok letterpress cornhole. Dreamcatcher tattooed hot chicken gatekeep, glossier salvia 8-bit cred. Fit lomo chillwave cold-pressed humblebrag narwhal. Meggings edison bulb fanny pack irony af pug pok pok whatever vexillologist vibecession cred butcher trust fund chia. - -## Bitters kale chips chambray activated charcoal - -wolf keffiyeh hell of selfies. Wolf readymade shoreditch flexitarian venmo single-origin coffee, knausgaard fit actually street art cold-pressed iPhone gatekeep. Migas bruh adaptogen semiotics marfa pickled yuccie. Locavore normcore lomo, shoreditch fashion axe actually glossier iPhone photo booth blue bottle DIY XOXO williamsburg. Pinterest whatever taxidermy, kale chips prism XOXO schlitz twee tote bag woke swag. Wayfarers fashion axe heirloom humblebrag synth. Whatever succulents PBR&B, pop-up enamel pin echo park tonx stumptown taiyaki. diff --git a/src/config.js b/src/config.js deleted file mode 100644 index ef28012..0000000 --- a/src/config.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * ConfigStore - * - * - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ -class ConfigStore { - - constructor() { - if (!ConfigStore.instance) { - ConfigStore.instance = this; - this._data = {} - } - - return ConfigStore.instance; - } - - /** - * set value by key - * - * @param {String} key - * @param {String|Object} value - * - */ - set(key, value) { - this._data[key] = value - } - - /** - * get value by key - * - * @param {String} key - * @return {String|Object} - */ - get(key) { - - if (!this._data?.[key]) { - throw new Error(key + ' not found in ConfigStore!') - } - - return this._data[key] - } -} - -// create instance -const instance = new ConfigStore(); - -module.exports = instance \ No newline at end of file diff --git a/src/engines/helpers.js b/src/engines/helpers.js deleted file mode 100644 index fba26db..0000000 --- a/src/engines/helpers.js +++ /dev/null @@ -1,53 +0,0 @@ -const path = require('path') -const fs = require('fs') - -const Media = require('./../factories/media.js') - -/** - * asset - checks manifest.json for given path and return - * file path with id for cache busting - * - * - * @param {String} publicPath - * - */ - -function asset(staticPath) { - - // getting basePath - let result = staticPath - - // path to mix-manifest - const file = path.join(path.resolve()) + 'mix-manifest.json' - - if (fs.existsSync(file)) { - - const manifest = fs.readFileSync(file) - const files = JSON.parse(manifest) - - if (files[staticPath]) { - result = files[staticPath] - } - } - - return result -} - -/** - * asset - checks manifest.json for given path and return - * file path with id for cache busting - * - * - * @param {String} publicPath - * - */ - -async function resize(src, sizes, options, done) -{ - const media = new Media() - - src = await media.resize(src, sizes, options) - done(null, src) -} - -module.exports = { asset, resize } \ No newline at end of file diff --git a/src/engines/nunjucks.js b/src/engines/nunjucks.js deleted file mode 100644 index aaccfd8..0000000 --- a/src/engines/nunjucks.js +++ /dev/null @@ -1,99 +0,0 @@ -const nunjucks = require('nunjucks') -const fs = require('fs') -const assign = require('assign-deep') -const { minify } = require('html-minifier') - -const configStore = require('./../config.js') -const { asset, resize } = require('./helpers.js') -const PageQuery = require('./../queries/pages.js') -const dayjs = require('dayjs') - -/** - * nunjucks - * - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ -class Engine { - - /** - * - * - * @param {string} views - * @param {object} site - * @param {object} options - * - */ - constructor(views, site, options) { - - // merge data - this._options = assign({}, { - autoescapes: true, - throwOnUndefined: true - }, options) - - this.nunjucks = nunjucks.configure(views, this._options) - - // add filter: resize - this.nunjucks.addFilter('resize', (...args) => { - const done = args.pop() - const options = args?.[2] ? {} : args[2] - - resize(args[0], args[1], options, done) - }, true) - - // adding defaults for view, data from site.yml, functions and pageQuery - this._defaults = { - site: site, - asset: asset, - dayjs: dayjs, - pageQuery: new PageQuery(configStore.get('source')) - } - } - - /** - * render - * - * @param {object} page - * @param {function} done - * - */ - render(page, done) { - - // merge data - const data = assign({ - page: page - }, this._defaults) - - this.nunjucks.render(data.page.view, data, (error, response) => { - - if (error) { - console.error(error) - } - - const options = configStore.get('options') - - // if options minifyHtml is set, minify html, but only if page has type html - if (options.minifyHtml === true && data.page.type === 'html') { - response = minify(response, { - removeComments: true, - collapseWhitespace: true, - keepClosingSlash: true, - removeOptionalTags: false - }) - - // remove empty lines - } else { - response = response.replace(/^(?:[\t ]*(?:\r?\n|\r))+/gm, '') - } - - done(error, response) - }) - } - -} - -module.exports = Engine \ No newline at end of file diff --git a/src/factories/block.js b/src/factories/block.js deleted file mode 100644 index 4234165..0000000 --- a/src/factories/block.js +++ /dev/null @@ -1,49 +0,0 @@ -const path = require('path') -const parseMarkdownFile = require('./../parsers/markdown.js') - -const assign = require('assign-deep') - -/** - * 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 - } - - /** - * - * - * @return {object} - * - */ - get() { - return assign({ - 'content': this._content - }, this._fields) - } -} - -module.exports = Block \ No newline at end of file diff --git a/src/factories/media.js b/src/factories/media.js deleted file mode 100644 index 9fe420f..0000000 --- a/src/factories/media.js +++ /dev/null @@ -1,99 +0,0 @@ -const path = require('path') -const fs = require('fs') -const sharp = require('sharp') -const mkdirp = require('mkdirp') -const crypto = require('crypto') -const slugify = require('slugify') - -const configStore = require('./../config.js') - -/** - * - * - */ -class Media { - - constructor() { - this._DIR_ASSETS = '/assets/' - } - - /** - * - * @param {string} src - * @param {object} sizes - * @param {Object} [options={}] - * @return {string} - * - */ - async resize(src, sizes, options = {}) { - - this._extension = path.extname(src) - this._filename = slugify(path.basename(src, this._extension)) - - this._process = await sharp(configStore.get('source') + '/' + src) - - // resize without options and with options - if (Object.getOwnPropertyNames(options).length === 0) { - await this._process - .resize(sizes) - } else { - this._process - .resize(sizes, options) - } - - // optimize - this._optimize() - - const fileBuffer = await this._process - .toBuffer() - - const relativeDestinationPath = this._DIR_ASSETS + this._resolveRelativeDestinationPath(fileBuffer) - - // create directories and write file - mkdirp.sync(configStore.get('destination') + relativeDestinationPath) - fs.writeFileSync(configStore.get('destination') + relativeDestinationPath + '/' + this._filename + this._extension, fileBuffer) - - return relativeDestinationPath + '/' + this._filename + this._extension - } - - /** - * @TODO much nicer to add a hook system so behavior can be change - * - * - * @param {string} extension - * - */ - _optimize() { - if (this._extension === '.gif') { - this._process - .gif({ - reoptimise: true - }) - } else { - - // change extension - this._extension = '.webp' - this._process - .webp({ - lossless: true - }) - } - } - - /** - * resolve path to write file, hash will be get = fileBuffer and - * - * - * @param {object} fileBuffer - * @return {string} - * - */ - _resolveRelativeDestinationPath(fileBuffer) { - const hash = crypto.createHash('sha1') - hash.update(fileBuffer) - - return hash.digest('hex').match(new RegExp('.{1,8}', 'g')).join('/') - } -} - -module.exports = Media \ No newline at end of file diff --git a/src/factories/page.js b/src/factories/page.js deleted file mode 100644 index 814eaf3..0000000 --- a/src/factories/page.js +++ /dev/null @@ -1,111 +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) - - // fields merge by default values - this._fields = merge({ - view: 'page.njk', - type: 'html', - meta: { - robots: 'index' - } - }, result.fields) - - // adding filename for html as pathname and relative path in structure - this._filename = this._resolveFilename(file) - this._pathname = this._resolvePathname(parent) - - 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 + '.' + this._fields.type - } - - /** - * 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/factories/sitemap.js b/src/factories/sitemap.js deleted file mode 100644 index 1fd12f7..0000000 --- a/src/factories/sitemap.js +++ /dev/null @@ -1,111 +0,0 @@ -const { XMLParser, XMLBuilder, XMLValidator} = require('fast-xml-parser') -const dayjs = require('dayjs') - -/** - * - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ -class Sitemap { - - /** - * - * - * @param {[type]} site - * @param {[type]} pages - * - */ - constructor(site) { - this._site = site - this._urls = [] - } - - /** - * adding page to urls of sitemap, check if page is valid for sitemap - * - * @param {object} page - * - */ - addPage(page) { - if (this._isValid(page)) { - this._urls.push({ - loc: 'https://' + this._site.domain + page.pathname + '/' + page.filename, - lastmod: dayjs().format() - }) - } - } - - /** - * get xml as string - * - * @return {string} - * - */ - getXmlAsString() { - return this._createXml(this._urls) - } - - /** - * check if robots has a noindex - * - * @param {object} page - * @return {boolean} - * - */ - _isValid(page) { - - 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 - return; - } - }) - } - - if (page.type !== 'html') { - result = false - } - - return result - } - - /** - * create xml with urls and return it as string - * - * @param {object} urls - * @return {string} - * - */ - _createXml(urls) { - - // builder for XML - const builder = new XMLBuilder({ - format: true, - processEntities: false, - ignoreAttributes: false, - attributeNamePrefix: '@' - }) - - const xmlString = builder.build({ - '?xml': { - '@version': '1.0', - '@encoding': 'UTF-8' - }, - 'urlset': { - '@xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9', - 'url': urls - } - }) - - return xmlString - } -} - -module.exports = Sitemap \ No newline at end of file diff --git a/src/parsers/markdown.js b/src/parsers/markdown.js deleted file mode 100644 index 8a3cb93..0000000 --- a/src/parsers/markdown.js +++ /dev/null @@ -1,42 +0,0 @@ -const yaml = require('js-yaml') -const { marked } = require('marked') - -/** - * parse string of file, parse yaml and parse markdown - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ - -function parseMarkdownFile(fileString) { - - // regex get yaml section and markdown - // thanks to, https://github.com/getgrav/grav - const regex = new RegExp(/^(---\n(.+?)\n---){0,}(.*)$/gs) - const matches = regex.exec(fileString) - - const result = { - fields: undefined, - content: '' - } - - // check if yaml section not exists throw error - if (matches?.[2]) { - try { - result.fields = yaml.load(matches[2]) - } catch (error) { - throw new Error('Yaml has errors!') - } - } - - // if markdown section exits parse it to html 6565 - if (matches?.[3]) { - result.content = marked.parse(matches[3]) - } - - return result -} - -module.exports = parseMarkdownFile \ No newline at end of file diff --git a/src/parsers/yaml.js b/src/parsers/yaml.js deleted file mode 100644 index 7b988e3..0000000 --- a/src/parsers/yaml.js +++ /dev/null @@ -1,25 +0,0 @@ -const yaml = require('js-yaml') - -/** - * parse string of file and only parse yaml - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ - -function parseYamlFile(file) { - - let config - - try { - config = yaml.load(file) - } catch (error) { - throw new Error('parseYamlFile: Yaml has errors!') - } - - return config -} - -module.exports = parseYamlFile \ No newline at end of file diff --git a/src/queries/blocks.js b/src/queries/blocks.js deleted file mode 100644 index baba849..0000000 --- a/src/queries/blocks.js +++ /dev/null @@ -1,130 +0,0 @@ -const fs = require('fs') -const path = require('path') - -const BlockFactory = require('./../factories/block.js') - -/** - * search, filter and find pages - * - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ - -class Blocks { - - /** - * - * - * @param {string} dirPath - * - */ - constructor(dirPath) { - - this.FILE_EXTENSION = '.md' - this.DIRECTORY_BLOCKS = '_blocks' - - this._dirPath = dirPath + '/' + this.DIRECTORY_BLOCKS; - this._results = {} - } - - /** - * - * - * @return {array} - */ - find() { - - if (fs.existsSync(this._dirPath)) { - this._findFiles(this._dirPath) - } - - return this._results - } - - /** - * find files - * - * @param {string} dirPath - * @param {Object} [parent = ''] - * - */ - _findFiles(dirPath, parent = '') { - - // - const files = fs.readdirSync(dirPath, { - withFileTypes: true - }) - - files.forEach((file) => { - - // skip for file that is not markdown - if (file.isFile() && path.extname(file.name) !== this.FILE_EXTENSION) { - return; - } - - // if directory going deep - if (file.isDirectory()) { - this._findFiles(dirPath, parent + '/' + file.name) - } - - // get file - const fileString = this._getFile(file, dirPath + parent) - - // skip if empty - if (!fileString) { - return; - } - - // create page object and add to page - const block = new BlockFactory(fileString) - const blockname = this._parseBlockname(file.name) - - if (!this._results[blockname]) { - this._results[blockname] = [] - } - - this._results[blockname].push(block.get()) - }) - } - - /** - * remove '.md' and also ordering number = filename - * - * @param {string} filename - * @return {string} - * - */ - _parseBlockname(filename) { - const regex = new RegExp(/[-_]?[0-9]*\b.md\b$/) - return filename.replace(regex, '') - } - - /** - * get file content - * - * @param {string} slug - * @param {string} sourcePath - * @return {mixed} - * - */ - _getFile(file, dirPath) { - - // file - let result = null - - // path of file, first try with slug - let filePath = dirPath + '/' + file.name - - if (fs.existsSync(filePath) && file.isFile()) { - result = fs.readFileSync(filePath, 'utf8') - } - - return result - } - -} - -module.exports =Blocks \ No newline at end of file diff --git a/src/queries/pages.js b/src/queries/pages.js deleted file mode 100644 index f674ca6..0000000 --- a/src/queries/pages.js +++ /dev/null @@ -1,188 +0,0 @@ -const fs = require('fs') -const path = require('path') -const { - Filter, orderBy, reduce -} = require('@helpers/siteomat-query') - -const PageFactory = require('./../factories/page.js') -const BlocksQuery = require('./../queries/blocks.js') - -/** - * Pages - search, filter and find pages - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ - -class Pages { - - /** - * - * - * @param {string} dirPath - * - */ - constructor(dirPath) { - - // constants - this.FILE_EXTENSION = '.md' - this.FILE_INDEX = 'index' - this.DIRECTORY_BLOCKS = '_blocks' - - // default options for find - this._options = { - parent: '', - deep: -1 - } - - this._dirPath = dirPath - this._results = [] - } - - /** - * find pages - * - * @param {Object} [options={}] - * @return {array} - * - */ - find(options = {}) { - this._results = [] - this._count = 0 - - options = Object.assign({}, this._options, options) - - if (options.filter) { - this._filter = new Filter(options.filter) - } - - this._findFiles(this._dirPath, options) - - // - if (options.orderBy && options.orderBy.length > 0) { - this.results = orderBy(options.orderBy, this._results) - } - - if (options.limit || options.offset) { - this._results = reduce(options, this._results) - } - - return this._results - } - - /** - * find files - * - * @param {[type]} dirPath [description] - * @param {Object} [parameters={}] [description] - * @param {Object} [options={}] [description] - * @return {[type]} - * - */ - _findFiles(dirPath, options) { - - // getting all files - const files = fs.readdirSync(dirPath + options.parent, { - withFileTypes: true - }) - - files.forEach((file) => { - - // skip for file that is not markdown - if (file.isFile() && path.extname(file.name) !== this.FILE_EXTENSION ) { - return; - } - - // skip for file that is index but not root - if (file.isFile() && file.name === (this.FILE_INDEX + this.FILE_EXTENSION) && options.parent !== '') { - return; - } - - // skip for directory that contains partials - if (file.isDirectory() && file.name === this.DIRECTORY_BLOCKS) { - return; - } - - // if directory going deep - if (file.isDirectory() && (options.deep > 0 || options.deep === -1)) { - - if (options.deep > 0) { - options.deep-- - } - - const childrenOptions = Object.assign({}, options, { - 'parent': options.parent + '/' + file.name - }) - - this._findFiles(dirPath, childrenOptions) - } - - // get file - const content = this._getFile(file, dirPath + options.parent) - - // skip if empty - if (!content) { - return; - } - - // check if - const blocks = this._getBlocks(dirPath + options.parent + '/' + file.name) - - // create page object and add to page - const page = new PageFactory(file, options.parent, content, blocks) - - // check for filters and skip - if (this._filter && !this._filter.validate(page.get())) { - return; - } - - this._results.push(page.get()) - }) - } - - /** - * - * - * @param {string} dirPath - * @return {array} - * - */ - _getBlocks(dirPath) { - const blocksQuery = new BlocksQuery(dirPath) - return blocksQuery.find() - } - - /** - * get file content - * - * @param {string} slug - * @param {string} sourcePath - * @return {mixed} - * - */ - _getFile(file, dirPath) { - - // file - let result = null - - // path of file, first try with slug - let filePath = dirPath + '/' + file.name - - if (fs.existsSync(filePath) && file.isFile()) { - result = fs.readFileSync(filePath, 'utf8') - } else { - filePath = dirPath + '/' + file.name + '/' + this.FILE_INDEX + this.FILE_EXTENSION - - if (fs.existsSync(filePath)) { - result = fs.readFileSync(filePath, 'utf8') - } - } - - return result - } - -} - -module.exports = Pages diff --git a/src/siteomat.js b/src/siteomat.js deleted file mode 100644 index b4aab02..0000000 --- a/src/siteomat.js +++ /dev/null @@ -1,118 +0,0 @@ -const fs = require('fs') -const path = require('path') -const mkdirp = require('mkdirp') -const assign = require('assign-deep') - -const configStore = require('./config.js') - -const Engine = require('./engines/nunjucks.js') -const Sitemap = require('./factories/sitemap.js') - -const PagesQuery = require('./queries/pages.js') -const parseYamlFile = require('./parsers/yaml.js') - -/** - * Siteomat - * - * - * - * @author Björn Hase - * @license http://opensource.org/licenses/MIT The MIT License - * @link https://gitea.node001.net/HerrHase/siteomat-webpack-plugin.git - * - */ -class Siteomat { - - /** - * - * - * @param {string} source - * @param {string} destination - * - */ - constructor(source, views, options = {}) { - - if (options.destination === undefined) { - throw new Error('Destination is undefined') - } - - this._source = source - this._views = views - this._destination = options.destination - - // fill singleton for configuration - configStore.set('source', source) - configStore.set('destination', this._destination) - configStore.set('views', views) - configStore.set('options', assign({ - 'minifyHtml': true - }, options)) - - // get config for site - if (fs.existsSync(this._source + '/site.yml')) { - const file = fs.readFileSync(this._source + '/site.yml', 'utf8') - this._site = parseYamlFile(file) - } else { - throw new Error('site.yml not found in ' + this._source + '!') - } - - if (fs.existsSync(this._source + '/json.yml')) { - const file = fs.readFileSync(this._source + '/json.yml', 'utf8') - this._json = parseYamlFile(file) - } - - configStore.set('site', this._site) - - this._engine = new Engine(views, this._site) - } - - /** - * let it rain \o/ - * - */ - run() { - const query = new PagesQuery(this._source) - const results = query.find() - - const sitemap = new Sitemap(this._site) - - // run through pages and generate html files - results.forEach((page, index) => { - this._engine.render(page, (error, content) => { - - // show errors - if (error) { - console.error(error) - } - - // if no content show error message - if (!content) { - console.error('Error! Rendering Page ' + '"' + page.filename + '" is null') - return; - } - - // create directories and write file = page - mkdirp(this._destination + page.pathname).then(() => { - fs.writeFileSync(this._destination + page.pathname + '/' + page.filename, content) - }) - - sitemap.addPage(page) - - // if run is finish, write sitemap.xml - if ((index + 1) === results.length) { - fs.writeFileSync(this._destination + '/sitemap.xml', sitemap.getXmlAsString()) - } - - }) - }) - - if (this._json) { - for (const [name, options] of Object.entries(this._json)) { - const json = query.find(options) - fs.writeFileSync(this._destination + '/' + name + '.json', JSON.stringify(json)) - } - } - } -} - -module.exports = Siteomat diff --git a/test.js b/test.js deleted file mode 100644 index 721a0c9..0000000 --- a/test.js +++ /dev/null @@ -1,8 +0,0 @@ -const Siteomat = require('./src/siteomat.js') - -const siteomat = new Siteomat('./example/site', './example/views', { - 'destination': './public', - 'minifyHtml': false -}) - -siteomat.run() diff --git a/test/blocks.js b/test/blocks.js deleted file mode 100644 index 812bf60..0000000 --- a/test/blocks.js +++ /dev/null @@ -1,24 +0,0 @@ -const { assert } = require('chai') -const fs = require('fs') - -describe('Blocks', function () { - - // get function parseMarkdownFile - const BlocksQuery = require('./../src/queries/blocks.js') - - const blocksQuery = new BlocksQuery('./ressources') - const results = blocksQuery.find() - - // check results - it('block is array', function() { - assert.isArray(results.block) - }) - - it('block has length of 2', function() { - assert.equal(results.block.length, 2) - }) - - it('title in first block are equal', function() { - assert.equal(results.block[0].title, 'health goth DIY tattooed') - }) -}) diff --git a/test/parserMarkdown.js b/test/parserMarkdown.js deleted file mode 100644 index 88ee59f..0000000 --- a/test/parserMarkdown.js +++ /dev/null @@ -1,41 +0,0 @@ -const { assert } = require('chai') -const fs = require('fs') - -describe('Parser Markdown', function () { - - // default file - const markdownData = fs.readFileSync('./ressources/default.md', 'utf8') - - // get function parseMarkdownFile - const parseMarkdownFile = require('./../src/parsers/markdown.js') - - // start parsing - const result = parseMarkdownFile(markdownData) - - // check results - it('fields exists', function() { - assert.notEqual(result.fields, undefined) - }) - - it('fields is object', function() { - assert.isObject(result.fields) - }) - - it('fields are valid', function() { - assert.deepEqual(result.fields, { - title: 'health goth DIY tattooed', - view: 'page.njk', - meta: { - description: 'DSA yes plz hot chicken green juice' - } - }) - }) - - it('content exists', function() { - assert.notEqual(result.content, '') - }) - - it('content has html', function() { - assert.match(result.content, /

Normcore cold-pressed ramps DSA<\/h2>/) - }) -})