12 local title = table.concat({...}, " "); |
12 local title = table.concat({...}, " "); |
13 if #title == 0 then |
13 if #title == 0 then |
14 title = os.date("New Post %Y-%m-%d"); |
14 title = os.date("New Post %Y-%m-%d"); |
15 end |
15 end |
16 |
16 |
17 local filename = make_short_title(title); |
17 local filename = posts_dir..make_short_title(title)..".markdown"; |
18 print(posts_dir..filename) |
18 print("Creating post: "..filename) |
19 local f = io.open(posts_dir..filename..".markdown", "r"); |
19 local f = io.open(filename, "r"); |
20 if f then print("File already exists or is unreable"); return; end |
20 if f then print("File already exists or is unreadable"); return; end |
21 f = io.open(posts_dir..filename..".markdown", "w+"); |
21 f = io.open(filename, "w+"); |
22 if not f then |
22 if not f then |
23 print("File not writeable"); |
23 print("File not writeable"); |
|
24 return; |
24 end |
25 end |
25 |
26 |
26 -- YAML |
27 -- YAML |
27 --f:write(" |
28 f:write("---\n"); |
|
29 f:write("title: ", title, "\n"); |
|
30 f:write("layout: post\n"); |
|
31 f:write("tags: \n"); |
|
32 f:write("x-published: \n"); |
|
33 f:write("---\n\n"); |
|
34 f:close(); |
|
35 local blog_editor = os.getenv("BLOG_EDITOR"); |
|
36 if blog_editor then |
|
37 blog_editor = blog_editor:gsub("%U+", { LINE = "8", POST = filename }); |
|
38 else |
|
39 blog_editor = (os.getenv("EDITOR") or "nano").." +8 "..filename; |
|
40 end |
|
41 os.execute(blog_editor); |
28 end |
42 end |
29 |
43 |
30 function commands.help() |
44 function commands.help() |
31 print "Jorvick - Blog Generator" |
45 print "Jorvick - Blog Generator" |
32 print "" |
46 print "" |