# HG changeset patch # User Matthew Wild # Date 1248130183 -3600 # Node ID e784e417a3e211f08de06754c95bb65aeb6e3c06 # Parent 7e9c3f32ec0a0d022e7b2759ff9d3b4952b2fa45 Add publish command to jorvick diff -r 7e9c3f32ec0a -r e784e417a3e2 jorvick --- a/jorvick Mon Jul 20 11:42:54 2009 +0100 +++ b/jorvick Mon Jul 20 23:49:43 2009 +0100 @@ -8,6 +8,29 @@ require "jorvick.build"; end +function commands.publish(post) + local f, err = io.open(post); + if not f then + print("Can't open post: "..(err or "unknown error")); + end + + local f2, err = io.open(post..".published", "w+"); + local in_header; + for line in f:lines() do + if in_header == nil and line:match("^%-%-%-%s*$") then + in_header = true; + elseif in_header == true and line:match("^%-%-%-%s*$") then + f2:write("published: "..os.date("!%Y-%m-%dT%H:%M:%SZ"), "\n"); + in_header = false; + end + f2:write(line, "\n"); + end + f:close(); + f2:close(); + os.rename(post..".published", post); + print("Post marked as published. Run build to update site."); +end + function commands.create(...) local title = table.concat({...}, " "); if #title == 0 then