From bacef6a2a6f180275c6f249ba88a2a90c317c06e Mon Sep 17 00:00:00 2001 From: HerrHase Date: Sun, 19 Feb 2023 17:38:18 +0100 Subject: [PATCH] adding #2 --- ressources/_blocks/data.md | 14 ++++++++++++++ src/queries/blocks.js | 32 ++++++++++++++++++++++++-------- test/blocks.js | 20 +++++++++++++++++++- 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 ressources/_blocks/data.md diff --git a/ressources/_blocks/data.md b/ressources/_blocks/data.md new file mode 100644 index 0000000..c8f8909 --- /dev/null +++ b/ressources/_blocks/data.md @@ -0,0 +1,14 @@ +--- +title: "Data" +--- +## 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/queries/blocks.js b/src/queries/blocks.js index baba849..cc2abee 100644 --- a/src/queries/blocks.js +++ b/src/queries/blocks.js @@ -53,7 +53,7 @@ class Blocks { */ _findFiles(dirPath, parent = '') { - // + // getting block files const files = fs.readdirSync(dirPath, { withFileTypes: true }) @@ -62,7 +62,7 @@ class Blocks { // skip for file that is not markdown if (file.isFile() && path.extname(file.name) !== this.FILE_EXTENSION) { - return; + return } // if directory going deep @@ -75,18 +75,22 @@ class Blocks { // skip if empty if (!fileString) { - return; + 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] = [] - } + if (this._isArray(file.name)) { + if (!this._results[blockname]) { + this._results[blockname] = [] + } - this._results[blockname].push(block.get()) + this._results[blockname].push(block.get()) + } else { + this._results[blockname] = block.get() + } }) } @@ -102,6 +106,18 @@ class Blocks { return filename.replace(regex, '') } + /** + * remove '.md' and also ordering number = filename + * + * @param {string} filename + * @return {string} + * + */ + _isArray(filename) { + const regex = new RegExp(/[-_]?[0-9]\b.md\b$/) + return regex.test(filename) + } + /** * get file content * @@ -127,4 +143,4 @@ class Blocks { } -module.exports =Blocks \ No newline at end of file +module.exports =Blocks diff --git a/test/blocks.js b/test/blocks.js index 812bf60..1441e6c 100644 --- a/test/blocks.js +++ b/test/blocks.js @@ -1,7 +1,7 @@ const { assert } = require('chai') const fs = require('fs') -describe('Blocks', function () { +describe('Blocks / Array', function () { // get function parseMarkdownFile const BlocksQuery = require('./../src/queries/blocks.js') @@ -22,3 +22,21 @@ describe('Blocks', function () { assert.equal(results.block[0].title, 'health goth DIY tattooed') }) }) + +describe('Blocks / Single', 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.isObject(results.data) + }) + + it('block has length of 2', function() { + assert.equal(results.data.title, 'Data') + }) +})