open System.Text.RegularExpressions
let posts = System.IO.Directory.GetFiles("/home/roald/Dropbox/repos/GithubPages/_posts", "*.markdown")
let readLines filePath = System.IO.File.ReadLines(filePath) |> Seq.toArray
let (|Regex|_|) pattern input =
let m = Regex.Match(input, pattern)
if m.Success then Some(List.tail [ for g in m.Groups -> g.Value ])
else None
let jekyll_image_tag =
Array.map (fun line ->
match line with
| l when (l:string).Contains(".gif)") -> line // change this to not ignore .gif
| Regex @"!\[([\w\s\.\-]+)\]\(\/assets\/([\w\-\.\/]+)\)" [ alt; path ] -> $"{{%% picture {path} --alt {alt} %%}}"
| Regex @"!\[\]\(\/assets\/([\w\-\.\/]+)\)" [ path ] -> $"{{%% picture {path} %%}}"
| _ -> line
)
let writeToFile filename text = System.IO.File.WriteAllLines(filename, text)
posts
|> Array.map readLines
|> Array.map jekyll_image_tag
|> Array.iteri (fun i -> writeToFile posts[i])
wait for fix: https://github.com/rbuchberger/jekyll_picture_tag/issues/239