Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs')
- const path = require('path')
- const glob = require('glob-fs')()
- const moment = require('moment')
- const matter = require('gray-matter')
- const processFile = filename => {
- const fileObj = matter(fs.readFileSync(filename, 'utf8'))
- const dataObj = {
- content: fileObj.content,
- filename: path.basename(filename),
- slug: fileObj.data.title
- .toLowerCase()
- .replace(/ /g, '-')
- .replace(/[^\w-]+/g, ''),
- iso8601Date: moment(fileObj.data.date).format(),
- ...fileObj.data
- }
- return dataObj
- }
- module.exports.parse = dir => glob.readdirSync(dir).map(processFile)
Add Comment
Please, Sign In to add comment