Created
December 27, 2014 16:26
-
-
Save e-jigsaw/ac1beb1cf07d4bf3df9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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