Mon, 20 Jul 2009 11:42:54 +0100
Improve 'create' command - now automatically fills in metadata and opens an editor
#!/usr/bin/env lua require "jorvick.util" local commands = {}; function commands.build() require "jorvick.build"; end function commands.create(...) local title = table.concat({...}, " "); if #title == 0 then title = os.date("New Post %Y-%m-%d"); end 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("---\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() print "Jorvick - Blog Generator" print "" print "Commands:" print " create - Create a new blank post with a title" print " publish - Mark a post as published and stamp it with a date" print " build - Generate the HTML files and feed for all posts" print "" end local command = arg[1] or "help"; table.remove(arg, 1); (commands[command] or commands.help)(unpack(arg));