Add ability to add all files in a dir
This commit is contained in:
parent
222be9ed38
commit
4aee049ad9
7
lint_config.lua
Normal file
7
lint_config.lua
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
return {
|
||||||
|
whitelist_globals = {
|
||||||
|
["site.moon"] = {
|
||||||
|
"add"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
lint_config.moon
Normal file
7
lint_config.moon
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
whitelist_globals: {
|
||||||
|
["site.moon"]: {
|
||||||
|
"add"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
site.moon
45
site.moon
@ -1,48 +1,19 @@
|
|||||||
sitegen = require "sitegen"
|
sitegen = require "sitegen"
|
||||||
lfs = require "lfs"
|
lfs = require "lfs"
|
||||||
moon = require "moon"
|
|
||||||
|
|
||||||
path = "docs"
|
files = (path="docs") ->
|
||||||
files = ["#{path}/#{file}" for file in lfs.dir(path) when file != "." and file != ".."]
|
["#{path}/#{file}" for file in lfs.dir(path) when file != "." and file != ".."]
|
||||||
|
|
||||||
-- example = "an example string"
|
rootname = (str) -> string.gsub str, "%.+", ""
|
||||||
example = "docs/post1.md"
|
last = (list) -> list[#list]
|
||||||
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) ->
|
split = (str, delimiter) ->
|
||||||
[capture for capture in string.gmatch(str, "[^#{delimiter}]+")]
|
[capture for capture in string.gmatch str, "[^#{delimiter}]+"]
|
||||||
|
|
||||||
last = (list) -> list[#list]
|
target = (path, delimeter="/") ->
|
||||||
rootname = (str) -> string.gsub str, "%.+", ""
|
"/posts/#{rootname(last(split(path, delimeter)))}"
|
||||||
|
|
||||||
target = (file, delimeter="/") ->
|
|
||||||
"/posts/#{rootname(last(split(file, delimeter)))}"
|
|
||||||
|
|
||||||
sitegen.create =>
|
sitegen.create =>
|
||||||
@title = "Hello World"
|
@title = "Hello World"
|
||||||
add "index.md"
|
add "index.md"
|
||||||
add file, target: target file for _, file in ipairs files
|
add path, target: target(path) for _, path 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