Add ability to add all files in a dir

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 20:16:37 -07:00
parent b5afc1c350
commit 189299876b
3 changed files with 22 additions and 37 deletions

7
lint_config.lua Normal file
View File

@ -0,0 +1,7 @@
return {
whitelist_globals = {
["site.moon"] = {
"add"
}
}
}

7
lint_config.moon Normal file
View File

@ -0,0 +1,7 @@
{
whitelist_globals: {
["site.moon"]: {
"add"
}
}
}

View File

@ -1,48 +1,19 @@
sitegen = require "sitegen"
lfs = require "lfs"
moon = require "moon"
path = "docs"
files = ["#{path}/#{file}" for file in lfs.dir(path) when file != "." and file != ".."]
files = (path="docs") ->
["#{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"
rootname = (str) -> string.gsub str, "%.+", ""
last = (list) -> list[#list]
split = (str, delimiter) ->
[capture for capture in string.gmatch(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)))}"
target = (path, delimeter="/") ->
"/posts/#{rootname(last(split(path, 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)))}"
add path, target: target(path) for _, path in ipairs files!