From b5afc1c3508316ab2e8b054382cc710ddcca31e3 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Mon, 16 Jun 2025 20:16:37 -0700 Subject: [PATCH] WIP: add all files in dir --- docs/post2.md | 1 + site.moon | 45 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 docs/post2.md diff --git a/docs/post2.md b/docs/post2.md new file mode 100644 index 0000000..4c1af99 --- /dev/null +++ b/docs/post2.md @@ -0,0 +1 @@ +# post 2 diff --git a/site.moon b/site.moon index 969749e..82c21c3 100644 --- a/site.moon +++ b/site.moon @@ -1,23 +1,48 @@ sitegen = require "sitegen" lfs = require "lfs" +moon = require "moon" + +path = "docs" +files = ["#{path}/#{file}" for file in lfs.dir(path) when file != "." and file != ".."] + +-- example = "an example string" +example = "docs/post1.md" +split_path = [capture for capture in string.gmatch(example, "[^/]+")] +-- moon.p [name for i, name in ipairs split_path when i == #split_path] +filename = split_path[#split_path] +-- moon.p string.gsub(filename, ".md", "") +name = string.gsub(filename, ".md", "") attrdir = (path) -> for file in lfs.dir(path) if file != "." and file != ".." f = path .. '/' .. file - print "\t " .. f - attr = lfs.attributes(f) + print f + attr = lfs.attributes f assert type(attr) == "table" - attrdir(f) if attr.mode == "directory" - -- if attr.mode == "directory" - -- attrdir(f) - -- else - -- for name, value in pairs attr - -- print name, value + attrdir f if attr.mode == "directory" --- attrdir "www" +-- attrdir "docs" + +split = (str, delimiter) -> + [capture for capture in string.gmatch(str, "[^#{delimiter}]+")] + +last = (list) -> list[#list] +rootname = (str) -> string.gsub str, "%.+", "" + +target = (file, delimeter="/") -> + "/posts/#{rootname(last(split(file, delimeter)))}" sitegen.create => @title = "Hello World" add "index.md" - add "docs/post1.md", target: "/posts/post1" + add file, target: target file for _, file in ipairs files + + -- add file, target: "/posts/#{rootname(last(split(file, delimeter)))}" for _, file in ipairs files + + -- for _, file in ipairs files + -- split_path = split file, delimiter + -- filename = last split_path + -- name = rootname filename + -- add file, target: "/posts/#{rootname}" + -- add file, target: "/posts/#{rootname(last(split(file, delimeter)))}"