Skip to content

Instantly share code, notes, and snippets.

@e-jigsaw
Created December 27, 2014 16:26
Show Gist options
  • Save e-jigsaw/ac1beb1cf07d4bf3df9a to your computer and use it in GitHub Desktop.
Save e-jigsaw/ac1beb1cf07d4bf3df9a to your computer and use it in GitHub Desktop.
fs = require 'fs'
fs.readdir 'posts', (err, files)-> files.forEach (file)-> fs.readFile "posts/#{file}", (err, contents)->
contents = contents.toString().split '\n'
title = /# (.*)/.exec(contents[0])[1]
url = /(\d{4})-(\d{2})-(\d{2})-(.*)\.md/.exec file
contents[0] = "# [#{title}](/#{url[1]}/#{url[2]}/#{url[3]}/#{url[4]}.html)"
fs.writeFile "posts/#{file}", contents.join('\n'), (err)-> if err? then console.log err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment