Created
January 5, 2015 13:22
-
-
Save ToJans/f916860bf3543cd78fa1 to your computer and use it in GitHub Desktop.
Fsharp script used to migrate from octopress to hugo
This file contains hidden or 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
open System.IO | |
let oldpath = @"D:\dev\oldblog\source\_posts" | |
let newpath = @"D:\dev\blog\tojans.me\content\blog" | |
let migrate (fname:string) = | |
let (date,name) = fname.Substring(0,10),fname.Substring(11).ToLower() | |
let slug = name.Substring(0,name.Length - ".markdown".Length).ToLower() | |
let isNonDateLine (x:string) = x.StartsWith("date:") = false | |
let isNonAddThisLine (x:string) = | |
x.StartsWith("<div style=\"text-align:right\"><a class=\"addthis_button\"") = false | |
let addDateAndSlugAfterTitle (str:string) = | |
if str.StartsWith("title:") then | |
let newtitle = if str.Contains("\"") then | |
str | |
else | |
str.Replace("title: ! '","title: '") | |
"date: \"" + date + "\"\nslug: \"" + slug + "\"\n" + newtitle | |
else str | |
let getLines (fn:string) = | |
let fullfn = Path.Combine(oldpath,fn) | |
File.ReadLines(fullfn) | |
let outfn = Path.Combine(newpath,name) | |
let outfile = new StreamWriter(outfn) | |
fname | |
|> getLines | |
|> Seq.filter isNonDateLine | |
|> Seq.filter isNonAddThisLine | |
|> Seq.map addDateAndSlugAfterTitle | |
|> Seq.iter(fun l -> outfile.WriteLine(l)) | |
outfile.Close() | |
// let fname = "2004-11-30-croam-objective-analysis.markdown" | |
// let fname2 = "2014-11-27-about-dependent-typing-idris-and-the-road-to-valhalla.MARKDOWN" | |
// migrate fname;; | |
// migrate fname2;; | |
let dir = new DirectoryInfo(oldpath) | |
dir.GetFiles("*.markdown") | |
|> Seq.map (fun x -> x.Name) | |
|> Seq.iter migrate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment