From 6680d0c0c5cb56a3c9d1823dc58ff9d9fdc2b266 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 8 May 2025 19:27:13 -0700 Subject: [PATCH] Refactor --- site.moon | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/site.moon b/site.moon index bdc4383..a926b0e 100644 --- a/site.moon +++ b/site.moon @@ -1,19 +1,19 @@ sitegen = require "sitegen" lfs = require "lfs" -files = (path="docs") -> - ["#{path}/#{file}" for file in lfs.dir(path) when file != "." and file != ".."] - -rootname = (str) -> string.gsub str, "%.+", "" +rootname = (str) -> string.gsub str, "%..+", "" last = (list) -> list[#list] -split = (str, delimiter) -> +split = (str, delimiter="/") -> [capture for capture in string.gmatch str, "[^#{delimiter}]+"] -target = (path, delimeter="/") -> - "/posts/#{rootname(last(split(path, delimeter)))}" +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 != ".."} sitegen.create => @title = "Hello World" add "index.md" - add path, target: target(path) for _, path in ipairs files! + add path, target: target for path, target in pairs posts "docs"