From 3190c9388d31760f5792ef04a2db9e036e4531c2 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 9 May 2025 14:29:46 -0700 Subject: [PATCH] Refactor posts function to reduce line length --- site.moon | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/site.moon b/site.moon index b95247a..bb816b7 100644 --- a/site.moon +++ b/site.moon @@ -5,22 +5,16 @@ rootname = (str) -> result = string.gsub str, "%..+", "" result -last = (list) -> list[#list] - split = (str, delimiter="/") -> [capture for capture in string.gmatch str, "[^#{delimiter}]+"] -join = (first, last, delimiter="/") -> table.concat({first, last}, delimiter) -target = (path, prefix) -> join(prefix, rootname(last(split path))) - --- posts = (path=".") -> --- {join(path, file), target(file, "/posts") for file in lfs.dir path when file != "." and file != ".."} +last = (list) -> list[#list] +join = (first, last, delimiter="/") -> table.concat {first, last}, delimiter +target = (path, prefix) -> join prefix, rootname(last(split path)) posts = (path=".") -> - files = [file for file in lfs.dir(path) when file != "." and file != ".."] - tuples = for _, file in ipairs files - {join(path, file), target(file, "/posts")} - {unpack tup for tup in *tuples} + files = [file for file in lfs.dir path when file != "." and file != ".."] + {join(path, file), target(file, "/posts") for _, file in ipairs files} sitegen.create => @title = "Hello World"