From d8a9d1494f627caff4f106c603b6f8edf309c7e3 Mon Sep 17 00:00:00 2001 From: HerrHase Date: Sun, 19 Feb 2023 17:07:18 +0100 Subject: [PATCH] adding #8 --- README.md | 14 ++++++-- ressources/blog/article.md | 17 +++++++++ ressources/blog/index.md | 17 +++++++++ ressources/{default.md => index.md} | 0 src/factories/page.js | 53 +++++++++++++++++++++-------- test/pages.js | 44 ++++++++++++++++++++++++ test/parserMarkdown.js | 2 +- 7 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 ressources/blog/article.md create mode 100644 ressources/blog/index.md rename ressources/{default.md => index.md} (100%) create mode 100644 test/pages.js diff --git a/README.md b/README.md index d254205..124b2a5 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,18 @@ media: 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**. - +After parsing Markdown-Files a Page always this values, + +| Name | Type | Default | Description | +|-------------|-----------|----------|-------------| +| path | {String} | / | Full path with File | +| permalink | {String} | -1 | Full path without Extensions, index.html will be empty | +| filename | {String} | null | Name of File | +| hidden | {Boolean} | false | If hidden, file will not be written | +| blocks | {Object} | Object | Blocks of Directory | +| content | {String} | empty | Parsed Markdown | +| view | {String} | page.njk | Tempate to render file | + ## Nesting A Page can be a single Markdown-File, or a Directory with a index-File inside. diff --git a/ressources/blog/article.md b/ressources/blog/article.md new file mode 100644 index 0000000..dd527cf --- /dev/null +++ b/ressources/blog/article.md @@ -0,0 +1,17 @@ +--- +title: "article" +view: "article.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/ressources/blog/index.md b/ressources/blog/index.md new file mode 100644 index 0000000..c9a0769 --- /dev/null +++ b/ressources/blog/index.md @@ -0,0 +1,17 @@ +--- +title: "blog" +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/ressources/default.md b/ressources/index.md similarity index 100% rename from ressources/default.md rename to ressources/index.md diff --git a/src/factories/page.js b/src/factories/page.js index 814eaf3..e0f3eac 100644 --- a/src/factories/page.js +++ b/src/factories/page.js @@ -35,15 +35,25 @@ class Page { // fields merge by default values this._fields = merge({ view: 'page.njk', - type: 'html', + extensions: 'html', meta: { robots: 'index' - } + }, + hidden: false }, result.fields) // adding filename for html as pathname and relative path in structure this._filename = this._resolveFilename(file) - this._pathname = this._resolvePathname(parent) + this._slug = this._resolveSlug(this._filename) + this._path = this._resolvePath(parent) + + this._permalink = this._path + + if (this._slug) { + this._permalink = this._path + '/' + this._slug + } + + this._filename += '.' + this._fields.extensions this._content = result.content this._blocks = blocks @@ -58,14 +68,29 @@ class Page { */ get() { return assign({ - 'content' : this._content, - 'blocks' : this._blocks, - 'path' : this._pathname + '/' + this._filename, - 'filename' : this._filename, - 'pathname' : this._pathname + 'content' : this._content, + 'blocks' : this._blocks, + 'path' : this._path + '/' + this._filename, + 'permalink' : this._permalink, + 'filename' : this._filename }, this._fields) } + /** + * + * + */ + _resolveSlug(filename) { + + let slug = filename + + if (slug === 'index') { + slug = '' + } + + return slug + } + /** * create html-filename = filename * @@ -87,7 +112,7 @@ class Page { filename = slugify(filename) } - return filename + '.' + this._fields.type + return filename } /** @@ -97,15 +122,15 @@ class Page { * @return {string} * */ - _resolvePathname(parent) { - let pathname = parent + _resolvePath(parent, slug) { + let path = parent if (parent === '/') { - pathname = '' + path = '' } - return pathname + return path } } -module.exports = Page \ No newline at end of file +module.exports = Page diff --git a/test/pages.js b/test/pages.js new file mode 100644 index 0000000..1d98621 --- /dev/null +++ b/test/pages.js @@ -0,0 +1,44 @@ +const { assert } = require('chai') +const fs = require('fs') + +const PagesQuery = require('./../src/queries/pages.js') + +describe('Page /index.md', function () { + + const query = new PagesQuery('./ressources'); + const results = query.find() + + const page = results[2] + + it('fields is object', function() { + assert.isObject(page) + }) + + it('path', function() { + assert.equal(page.path, '/index.html') + }) + + it('permalink', function() { + assert.equal(page.permalink, '') + }) +}) + +describe('Page /blog/article.md', function () { + + const query = new PagesQuery('./ressources'); + const results = query.find() + + const page = results[0] + + it('fields is object', function() { + assert.isObject(page) + }) + + it('path', function() { + assert.equal(page.path, '/blog/article.html') + }) + + it('permalink', function() { + assert.equal(page.permalink, '/blog/article') + }) +}) diff --git a/test/parserMarkdown.js b/test/parserMarkdown.js index 88ee59f..d5b565d 100644 --- a/test/parserMarkdown.js +++ b/test/parserMarkdown.js @@ -4,7 +4,7 @@ const fs = require('fs') describe('Parser Markdown', function () { // default file - const markdownData = fs.readFileSync('./ressources/default.md', 'utf8') + const markdownData = fs.readFileSync('./ressources/index.md', 'utf8') // get function parseMarkdownFile const parseMarkdownFile = require('./../src/parsers/markdown.js')