WIP: add all files in dir
This commit is contained in:
parent
48f97c1e4a
commit
222be9ed38
1
docs/post2.md
Normal file
1
docs/post2.md
Normal file
@ -0,0 +1 @@
|
||||
# post 2
|
45
site.moon
45
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)))}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user