Add publish command to jorvick

Mon, 20 Jul 2009 23:49:43 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 20 Jul 2009 23:49:43 +0100
changeset 15
e784e417a3e2
parent 14
7e9c3f32ec0a
child 16
f5afa9d3d3c5

Add publish command to jorvick

jorvick file | annotate | diff | comparison | revisions
--- 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

mercurial