Add util module and move first helper function into it

Sat, 11 Jul 2009 02:14:33 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 11 Jul 2009 02:14:33 +0100
changeset 6
cf40d55f8122
parent 5
951de9625338
child 7
9ab155822b0b

Add util module and move first helper function into it

build.lua file | annotate | diff | comparison | revisions
util.lua file | annotate | diff | comparison | revisions
--- a/build.lua	Sat May 23 21:15:19 2009 +0100
+++ b/build.lua	Sat Jul 11 02:14:33 2009 +0100
@@ -1,6 +1,7 @@
 require "LuaTemplates.templates"
 require "LuaTemplates.parsers"
 require "lfs"
+require "util"
 
 -- Config --
 
@@ -68,10 +69,7 @@
 			-- Parse post_data according to extension, add to post list
 			--msg_info("Parsing %s...", post_filename) --:gsub("%.[^%.]+$", ""):match("[^/]+"));
 			post.content = templates.load(parsers[post_format](post_data)):render{ page = post };
-			post.shorttitle = post.title:gsub("%W+", "-"):lower():sub(1,45)
-			if #post.title:gsub("%W+", "-") > 45 then
-				post.shorttitle = post.shorttitle:gsub("%-%w+$", "");
-			end
+			post.shorttile = make_short_title(post.title);
 			post.url = base_url..post.shorttitle.."/"
 			post.post = post
 			post.updated = post.updated or os.date("!%Y-%m-%dT%H:%M:%SZ", lfs.attributes(post.path).modification);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util.lua	Sat Jul 11 02:14:33 2009 +0100
@@ -0,0 +1,9 @@
+
+-- Takes "Why I like fish" and returns "why-i-like-fish"
+function make_short_title(long_title)
+	local short_title = long_title:gsub("%W+", "-"):lower():sub(1,45)
+	if #long_title:gsub("%W+", "-") > 45 then
+		short_title = short_title:gsub("%-%w+$", "");
+	end
+	return short_title;
+end

mercurial