Skip to content

Instantly share code, notes, and snippets.

@e-jigsaw
Last active August 29, 2015 14:12
Show Gist options
  • Save e-jigsaw/9311442c27bd1e48f8b4 to your computer and use it in GitHub Desktop.
Save e-jigsaw/9311442c27bd1e48f8b4 to your computer and use it in GitHub Desktop.
fs = require 'fs'
fs.readdir 'posts', (err, files)-> files.forEach (filename)-> fs.readFile "posts/#{filename}", (err, file)->
text = file.toString().split('\n')
title = /title: "(.*)"/.exec(text[1])[1]
output = [].concat(["# #{title}", ''], text.slice(7)).join('\n')
fs.writeFile "posts/#{filename}", output, (err)-> if err? then console.log filename, err else console.log "convert success: #{filename}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment