This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 20:16:37 -07:00
parent 189299876b
commit 330a965765

View File

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