Guest User

Untitled

a guest
Mar 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. const fs = require('fs')
  2. const path = require('path')
  3. const glob = require('glob-fs')()
  4. const moment = require('moment')
  5. const matter = require('gray-matter')
  6.  
  7. const processFile = filename => {
  8. const fileObj = matter(fs.readFileSync(filename, 'utf8'))
  9. const dataObj = {
  10. content: fileObj.content,
  11. filename: path.basename(filename),
  12. slug: fileObj.data.title
  13. .toLowerCase()
  14. .replace(/ /g, '-')
  15. .replace(/[^\w-]+/g, ''),
  16. iso8601Date: moment(fileObj.data.date).format(),
  17. ...fileObj.data
  18. }
  19.  
  20. return dataObj
  21. }
  22.  
  23. module.exports.parse = dir => glob.readdirSync(dir).map(processFile)
Add Comment
Please, Sign In to add comment