miti.sh/site.moon
2025-05-09 14:21:04 -07:00

29 lines
872 B
Plaintext

sitegen = require "sitegen"
lfs = require "lfs"
rootname = (str) ->
result = string.gsub str, "%..+", ""
result
last = (list) -> list[#list]
split = (str, delimiter="/") ->
[capture for capture in string.gmatch str, "[^#{delimiter}]+"]
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 != ".."}
posts = (path=".") ->
files = [file for file in lfs.dir(path) when file != "." and file != ".."]
tuples = for _, file in ipairs files
{join(path, file), target(file, "/posts")}
{unpack tup for tup in *tuples}
sitegen.create =>
@title = "Hello World"
add "index.md"
add path, target: target for path, target in pairs posts "docs"