build.lua

changeset 2
80eb1f7784c4
parent 1
74deddff1202
child 3
f22a275a3a33
equal deleted inserted replaced
1:74deddff1202 2:80eb1f7784c4
6 6
7 dofile(arg[1] or ".blogrc") 7 dofile(arg[1] or ".blogrc")
8 8
9 posts_dir = posts_dir or "_posts/" 9 posts_dir = posts_dir or "_posts/"
10 layouts_dir = layouts_dir or "_layouts/" 10 layouts_dir = layouts_dir or "_layouts/"
11 output_dir = output_dir or "./"
11 -- - -- - -- 12 -- - -- - --
12 13
13 -- Logging -- 14 -- Logging --
14 function make_msg(prefix, name) return function (fmt, ...) print(prefix, string.format(fmt, ...)); end end 15 function make_msg(prefix, name) return function (fmt, ...) print(prefix, string.format(fmt, ...)); end end
15 msg_info, msg_warn, msg_error = make_msg("II", "info"), make_msg("WW", "warn"), make_msg("EE", "error"); 16 msg_info, msg_warn, msg_error = make_msg("II", "info"), make_msg("WW", "warn"), make_msg("EE", "error");
16 -- -- - -- -- 17 -- -- - -- --
17 18
18 -- Append '/' to end of posts_dir if necessary 19 -- Append '/' to end of posts_dir if necessary
19 posts_dir = posts_dir:gsub("([^/])$", "%1/") 20 posts_dir = posts_dir:gsub("([^/])$", "%1/")
21
22 -- Append '/' to end of output_dir if necessary
23 output_dir = output_dir:gsub("([^/])$", "%1/")
20 24
21 -- Append '/' to end of base_url if necessary 25 -- Append '/' to end of base_url if necessary
22 base_url = base_url:gsub("([^/])$", "%1/") 26 base_url = base_url:gsub("([^/])$", "%1/")
23 27
24 posts = {}; 28 posts = {};
114 msg_info(" - - - "); 118 msg_info(" - - - ");
115 119
116 local unpublished = 0; 120 local unpublished = 0;
117 for n, post in ipairs(posts) do 121 for n, post in ipairs(posts) do
118 if post.content and (not post.layout or layouts[post.layout]) then 122 if post.content and (not post.layout or layouts[post.layout]) then
119 lfs.mkdir(post.shorttitle); 123 lfs.mkdir(output_dir..post.shorttitle);
120 local outfile, err = io.open(post.shorttitle.."/index.html", "w+"); 124 local outfile, err = io.open(output_dir..post.shorttitle.."/index.html", "w+");
121 if outfile then 125 if outfile then
122 local layout = layouts[post.layout or "default"]; 126 local layout = layouts[post.layout or "default"];
123 127
124 -- Link to the previous and next published posts 128 -- Link to the previous and next published posts
125 local i = 1; 129 local i = 1;
161 msg_info("%s post%s published, %d post%s unpublished", #posts, #posts ~= 1 and "s" or "", unpublished, unpublished ~= 1 and "s" or ""); 165 msg_info("%s post%s published, %d post%s unpublished", #posts, #posts ~= 1 and "s" or "", unpublished, unpublished ~= 1 and "s" or "");
162 166
163 msg_info(" - - - "); 167 msg_info(" - - - ");
164 168
165 -- Do feed 169 -- Do feed
166 local atom = io.open("feed/atom.xml.new", "w+"); 170 local atom = io.open(output_dir.."feed/atom.xml.new", "w+");
167 atom:write[[<?xml version="1.0" encoding="UTF-8"?> 171 atom:write[[<?xml version="1.0" encoding="UTF-8"?>
168 <feed xmlns="http://www.w3.org/2005/Atom"> 172 <feed xmlns="http://www.w3.org/2005/Atom">
169 ]] 173 ]]
170 atom:write("\t<id>", base_url, "</id>\n"); 174 atom:write("\t<id>", base_url, "</id>\n");
171 atom:write("\t<title>", blog_title, "</title>\n"); 175 atom:write("\t<title>", blog_title, "</title>\n");

mercurial