From 9eb06e2789697ddcf13a5a929b9c3f68ad19f215 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 21 May 2025 20:58:11 -0700 Subject: [PATCH] WIP --- site.moon | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/site.moon b/site.moon index bd2b0d7..bc12720 100644 --- a/site.moon +++ b/site.moon @@ -43,16 +43,22 @@ rootname = (str) -> result = string.gsub str, "%..+", "" result -last = (list) -> list[#list] -join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter -reverse = (list={}) -> [item for item in *list[#list, 1, -1]] -target = (path, prefix) -> join prefix, rootname(last(common.split path, "/")) - extract_id = (source) -> string.match Path.filename(source), "%a[%w%-]+" extract_date = (source) -> string.match Path.filename(source), "%d+%-%d%d%-%d%d" format_date = (str) -> date(str)\fmt "%b %d, %Y" publish_date = (path) -> format_date extract_date path +last = (list) -> list[#list] +join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter +reverse = (list={}) -> [item for item in *list[#list, 1, -1]] +target = (path, prefix=".") -> + + a = rootname(last(common.split path, "/")) + b = a\gsub "#{escape_patt(extract_date(a) .. "-")}/?", "" + p b + b + Path.join prefix, a\gsub("#{escape_patt(extract_date(a) .. "-")}/?", "") + h = (word) -> word\sub(1, 1)\upper! t = (word) -> word\sub(2, -1)\lower! titleize = (word) -> h(word), t(word) @@ -105,9 +111,7 @@ documents = (path=".") -> {join(path, file), target(file, "/posts") for file in *files} clean = (target) -> - dirty = extract_date target - escaped = dirty\gsub("%-", "%%-") .. "%-" - target\gsub(escaped, "") + target\gsub "#{escape_patt(extract_date(target) .. "-")}/?", "" sitegen.create => @site_title = "WebDevCat.me" @@ -116,11 +120,11 @@ sitegen.create => @list_posts = list_posts @, template add_all = (name, files) -> - for path, target in pairs files + for path, _ in pairs files id = extract_id path add path, - target: clean(target) + target: clean(target(path, "/posts")) template: name is_a: name publish_date: publish_date path