From d854053e348ca2de9042c01cc3aa7c5aaa61b52f Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 9 May 2025 14:16:57 -0700 Subject: [PATCH] WIP: refactor to shorten line --- site.moon | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/site.moon b/site.moon index a926b0e..79b9f51 100644 --- a/site.moon +++ b/site.moon @@ -1,7 +1,10 @@ sitegen = require "sitegen" lfs = require "lfs" -rootname = (str) -> string.gsub str, "%..+", "" +rootname = (str) -> + result = string.gsub str, "%..+", "" + result + last = (list) -> list[#list] split = (str, delimiter="/") -> @@ -13,7 +16,22 @@ 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 != ".."} +path = "docs" + +names = [file for file in lfs.dir(path) when file != "." and file != ".."] + +tuples = for _, file in ipairs names + {join(path, file), target(file, "/posts")} + +new_posts = (path=".") -> + t = for _, file in ipairs names + {join(path, file), target(file, "/posts")} + t + +news = new_posts("docs") +posts = {unpack tup for tup in *news} + sitegen.create => @title = "Hello World" add "index.md" - add path, target: target for path, target in pairs posts "docs" + add path, target: target for path, target in pairs posts