# HG changeset patch # User Matthew Wild # Date 1248086574 -3600 # Node ID 7e9c3f32ec0a0d022e7b2759ff9d3b4952b2fa45 # Parent 39add8e7fa9947f092be4b46cd2bb1ba753ef04a Improve 'create' command - now automatically fills in metadata and opens an editor diff -r 39add8e7fa99 -r 7e9c3f32ec0a jorvick --- a/jorvick Tue Jul 14 02:07:18 2009 +0100 +++ b/jorvick Mon Jul 20 11:42:54 2009 +0100 @@ -14,17 +14,31 @@ title = os.date("New Post %Y-%m-%d"); end - local filename = make_short_title(title); - print(posts_dir..filename) - local f = io.open(posts_dir..filename..".markdown", "r"); - if f then print("File already exists or is unreable"); return; end - f = io.open(posts_dir..filename..".markdown", "w+"); + local filename = posts_dir..make_short_title(title)..".markdown"; + print("Creating post: "..filename) + local f = io.open(filename, "r"); + if f then print("File already exists or is unreadable"); return; end + f = io.open(filename, "w+"); if not f then print("File not writeable"); + return; end -- YAML - --f:write(" + f:write("---\n"); + f:write("title: ", title, "\n"); + f:write("layout: post\n"); + f:write("tags: \n"); + f:write("x-published: \n"); + f:write("---\n\n"); + f:close(); + local blog_editor = os.getenv("BLOG_EDITOR"); + if blog_editor then + blog_editor = blog_editor:gsub("%U+", { LINE = "8", POST = filename }); + else + blog_editor = (os.getenv("EDITOR") or "nano").." +8 "..filename; + end + os.execute(blog_editor); end function commands.help()