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 f attr = lfs.attributes f assert type(attr) == "table" attrdir f if attr.mode == "directory" -- 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 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)))}"