-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-post.fsx
37 lines (30 loc) · 869 Bytes
/
new-post.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Script to create a new blog post in drafts folder
open System
open System.IO
// First build the filname
let filename =
fsi.CommandLineArgs
|> Array.tail
|> Array.map (fun s -> s.ToLower())
|> String.concat "-"
// Make sure we've got a filename...
if String.IsNullOrWhiteSpace filename
then printfn "A new post requires a title"
else
if not (Directory.Exists "drafts") then
Directory.CreateDirectory("drafts") |> ignore
let title =
fsi.CommandLineArgs
|> Array.tail
|> String.concat " "
let content = [|
"---"
"layout: post"
(sprintf "title: %s" title)
"author: @recumbent"
"tags:"
"---"
|]
let filePath = sprintf "drafts/%s.md" filename
File.WriteAllLines(filePath, content)
printfn "New post file created as: %s" filePath