From bf20f4f6d97b8d2643f19ed7ac617c33a7f2ea6b Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 18 Jun 2017 12:35:49 +0200 Subject: refactor: metadata -> posts --- src/modules/metadata.js | 41 ----------------------------------------- src/modules/posts.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 41 deletions(-) delete mode 100644 src/modules/metadata.js create mode 100644 src/modules/posts.js (limited to 'src/modules') diff --git a/src/modules/metadata.js b/src/modules/metadata.js deleted file mode 100644 index f35031d..0000000 --- a/src/modules/metadata.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict' - -const fs = require('fs') -const path = require('path') -const matter = require('gray-matter') - -const options = { - lang: 'toml', - delims: '+++' -} - -function* lowercaseKeys (iterator) { - for (let [k, v] of iterator) { - yield [String(k).toLowerCase(), v] - } -} - -function canonicaliseMetadata (meta) { - if (meta.data) { - meta.data = new Map(lowercaseKeys(Object.entries(meta.data))) - } else { - meta.data = new Map() - } - return meta -} - -function getFileMetadata (filename) { - return canonicaliseMetadata(matter.read(filename, options)) -} - -function getFolderMetadata (folder) { - return fs - .readdirSync(folder) - .map(f => path.resolve(folder, f)) - .map(getFileMetadata) -} - -module.exports = { - getFileMetadata, - getFolderMetadata -} diff --git a/src/modules/posts.js b/src/modules/posts.js new file mode 100644 index 0000000..e005103 --- /dev/null +++ b/src/modules/posts.js @@ -0,0 +1,38 @@ +'use strict' + +const fs = require('fs') +const path = require('path') +const matter = require('gray-matter') + +const options = { + lang: 'toml', + delims: '+++' +} + +function* lowercaseKeys (iterator) { + for (let [k, v] of iterator) { + yield [String(k).toLowerCase(), v] + } +} + +function canonicaliseMetadata (meta) { + if (meta.data) { + meta.data = new Map(lowercaseKeys(Object.entries(meta.data))) + } else { + meta.data = new Map() + } + return meta +} + +function get (filename) { + return canonicaliseMetadata(matter.read(filename, options)) +} + +function getFolder (folder) { + return fs.readdirSync(folder).map(f => path.resolve(folder, f)).map(get) +} + +module.exports = { + get, + getFolder +} -- cgit 1.4.1